Here i am implementing an Image slider
My problem is when i hover my image slider i want to stop my css transition property.
I tried using addclass and removeclass but failed
Here is my code
HTML
<div id="container">
<img src="http://worksheetgenius.com/Next_button.jpg" width="106px;" id="right"/>
<img src="http://worksheetgenius.com/Previous_button.jpg" width="106px;" id="left"/>
<div id="slider">
<div id="slide1" class="slide transition">
<img src="http://s.cghub.com/files/Image/030001-031000/30883/37_max.jpg"/>
</div>
<div id="slide2" class="slide transition">
<img src="http://www.f-16.net/attachments/83_1093_207.jpg" />
</div>
<div id="slide3" class="slide transition">
<img src="http://www.sportbikes.net/forums/attachments/fz6/37654d1111746148-all-fz6-riders-show-us-your-bike-imag0005-edited-downscaled.jpg" />
</div>
<div id="slide4" class="slide transition">
<img src="http://3.bp.blogspot.com/-fpTz_1UegJM/TZ6eQWXTueI/AAAAAAAAASY/TsYJ5xZyixQ/s1600/banner_239.jpg" />
</div>
</div>
</div>
CSS
#slider
{
overflow:hidden;
height:363px;
position:absolute;
left:180px;
top:159px;
padding:0px;
margin:0px;
background: url("header_bg.jpg") repeat-x scroll 0 0 #FFFFFF;
width:1000px;
}
#slide1
{
position:absolute;
left:0px;
z-index:1;
}
.slide
{
position:absolute;
left:1000px;
}
.transition
{
-webkit-transition: all 0.3s;
transition: all 0.3s;
}
.notransition
{
-webkit-transition: none;
transition: none;
}
#right
{
position:absolute;
top: 287.5px;
right: 127px;
z-index: 99;
}
#left
{
position:absolute;
top: 287.5px;
left: 127px;
z-index: 99;
}
Script
var t=setInterval(function(){$("#right").click()},5000);
$(document).ready(function()
{
var present=1;
var next=2;
var total_slide=document.getElementById("slider").childElementCount;
$("#right").click(function()
{
present_slide="#slide"+present;
next_slide="#slide"+next;
$(present_slide).css("left","1000px");
$(next_slide).css("left","0px");
present++;
next++;
if(present==(total_slide+1))
{
present=1;
next=2;
for(i=1;i<=total_slide;i++)
{
$("#slide"+i).css("left","1000px");
}
$("#slide1").css("left","0px");
}
});
$("#left").click(function()
{
if(present==1)
{
next_slide="#slide"+total_slide;
present_slide="#slide"+present;
$(present_slide).css("left","1000px");
$(next_slide).css("left","0px");
present=total_slide;
next=1;
}else
{
next_slide="#slide"+(present-1);
present_slide="#slide"+present;
$(present_slide).css("left","1000px");
$(next_slide).css("left","0px");
present--;
next--;
}
if(next==0)
{
present=(total_slide-1);
next=total_slide;
}
});
$(".slide").on('mouseenter',function()
{ $(this).removeClass('transition').addClass('notransition');});
$(".slide").on('mouseleave',function()
{$(this).removeClass('notransition').addClass('transition');});
});
In the above provided code i used to classes transition and no transition.
I also tried with CSS as follows
.slide:hover
{
-webkit-transition: none;
transition: none;
}
I was doing a similar idea and I ended up using this cycle plugin for jquery Malsup Cycle. I then used this piece of code but you can find all of the options at the link above.
$(document).ready(function(){
$('#slider').cycle({
fx: 'scrollLeft',
speed: 1000,
timeout: 5000,
pause: 1
});
});
Setting the pause flag to one gets your desired functionality where it will stop animating on hover. I hope this helps!
HTML
<div id = "slider">
<div>
Slide 1
</div>
<div>
Slide 2
</div>
<div>
Slide 3
</div>
<div>
Slide 4
</div>
</div>
You just need to link to the plugin in the html and this should provide the desired functionality as I see it. You can put whatever content you want in the divs. I used a picture of our clients' logos with a short description as a banner on our company's page.
EDIT: I changed the selector to match the id that you used. HTML added.
Related
I'm somewhat new to Vue, and I'm working on trying to make a transition work. The outcome would look similar to the gif below. The element moving from right to left is one component in Vue, but the issue is I'm transitioning it from one Bootstrap column to another. From what I've seen online, there isn't an easy way to CSS transition while also changing the parent element, so what I've done is basically rendered the component twice, and delayed the second one. In the gif, you can see the point where it transitions and its a bit clunky.
I'm wondering if this is best practice, or if there's another, easier way to do this. Should I rework my whole structure to make them live under the same parent, and just change the position via CSS, or should I continue with what I've done and just work to smooth out the transition between the two elements?
<div class="d-flex align-items-center min-vh-100 hero">
<div class="container-fluid">
<div class="row hero-row d-flex">
<div class="col hero-left d-flex align-items-center">
<div class="w-100">
<transition appear name="fade-left" mode="out-in" >
<HeroNav v-if="$route.name!='Home'"/>
<h1 v-else>Hey, I'm George.</h1>
</transition>
</div>
</div>
<div class="col d-flex hero-right align-items-center">
<transition name="slide" mode="out-in">
<HeroNav v-if="$route.name=='Home'"/>
<div v-else>
</div>
</transition>
</div>
</div>
</div>
</div>
</template>
<script>
import HeroNav from '#/components/HeroNav.vue'
export default {
name: 'Hero',
components: { HeroNav }
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.hero {
background: #24292E;
height: 100%;
}
.hero-row {
height: 30em;
}
.hero-left {
border-right: 1px solid #AEC6CF;
}
.hero-left .nav-text{
float: right;
margin-right: 3em;
z-index: 1;
}
.hero-right .nav-text{
margin-left: 3em;
}
h1 {
color: #CFAEB5;
font-family: 'Lato', sans-serif;
font-size: 4rem !important;
font-weight: 100 !important;
text-align: right;
}
h3 {
color: #ffffff;
}
.fade-enter-active,
.fade-leave-active {
transition: all .5s ease;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
}
.fade-left-enter-active,
.fade-left-leave-active {
transition: all 1s ease;
transition-delay: .15s;
}
.fade-left-enter-from,
.fade-left-leave-to {
opacity: 0;
}
.slide-enter-active,
.slide-leave-active {
transition: all 1.7s cubic-bezier(.17,.67,0,1);
}
.slide-leave-to {
transform: translateX(-29.4em);
opacity: 1;
}
</style>```
i want to move an img by button click. I know this question has been asked a lot, but i couldnt use them.
Heres the relevant HTML:
<button class="ggE" (click)="gegenEnemy(chosenHero, actualEnemy);moveFist(); ...
<div class="col">
<img id="img" class="fist" src="...">
This is the function (typescript):
moveFist(): void {
document.getElementById('img').classList.add('fist');
}
And my css, which makes the picture move from left to right:
.fist {
width: 70px;
height: 70px;
position: relative;
animation-name: example;
animation-duration: 2s;
}
#keyframes example {
0% {left:50px; top:20px;}
100% {left:450px; top:20px;}
}
So why cant i connect it with a button click?
First of all validate your HTML code
<button class="ggE" onclick="moveFist();">button</button>
<div class="col">
<img id="img" class="" src="https://via.placeholder.com/150">
<div>
Edits:
function moveFist(){
document.getElementById("img").classList.remove("fist");
// element.offsetWidth = element.offsetWidth;
// Do this instead:
void img.offsetWidth;
document.getElementById("img").classList.add("fist");
}
set the width of img by it's offset width that is,
img.offsetWidth;
Can you something like this ?
function moveFist(){
document.getElementById("img").classList.remove("fist");
// element.offsetWidth = element.offsetWidth;
// Do this instead:
void img.offsetWidth;
document.getElementById("img").classList.add("fist");
}
img{
width: 70px;
height: 70px;
position: relative;
left:50px;
animation-duration: 2s;
top:20px;
}
.fist{
position:relative;
animation-name: example;
}
#keyframes example {
0% {left:50px; top:20px;}
100% {left:450px; top:20px;}
}
<button class="ggE" onclick="moveFist()">button</button>
<div class="col">
<img id="img" class="" src="https://via.placeholder.com/150">
<div>
I have the following HTML structure:
<div class="products-container">
{foreach from=$cart.products item=product}
<div class="product" data-id-product="{$product.id_product}" data-id-product-attribute="{$product.id_product_attribute}">
...
</div>
</div>
Now I have a javascript that can remove any div .product.
Is there a way to fade the deleted div out of the DOM to the right and animate the other divs 'moving up to the free space'?
A simple example
let btt = document.querySelector('button');
let products_cnt = document.querySelector('.products');
let products = document.querySelectorAll('.product');
products[0].addEventListener('transitionend', function() {
[...products].forEach((p) => p.parentNode.removeChild(p))
});
btt.addEventListener('click', function() {
this.setAttribute('disabled', 'disabled');
products_cnt.classList.add('products--delete');
})
div {
border: 1px #9bc solid;
height: 60px;
width: 200px;
margin: 10px;
color: #69A;
font: 1em system-ui;
}
button {
margin-bottom: 3em;
cursor: pointer; }
.products {
overflow-x: hidden; }
.product {
font-weight: bold;
transition: transform 1.5s 0s, opacity 1.25s 0s;
transform: translateX(0);
opacity: 1;
}
.products--delete .product {
transform: translateX(100vw);
opacity: 0;
}
<button type="button">Remove product/s</button>
<section class="products">
<div>Not a product</div>
<div class="product">Product</div>
<div class="product">Product</div>
<div>Not a product</div>
<div class="product">Product</div>
<div>Not a product</div>
</section>
Explanation: when you click the button the class .products--delete is added to the .products_container element: this starts a CSS transition over the .product elements.
Finally, when the transitionend event occurs on a single product element just remove from the DOM all products.
You can use css transitions in your CSS. The part of removing may be different for you. Please click the product to remove it.
let productsRy = Array.from(document.querySelectorAll(".product"));
productsRy.forEach((p,i)=>{
p.style.top = i * (3 + 1) * 16 +"px";
p.addEventListener("click",()=>{
container.removeChild(p);
productsRy = Array.from(document.querySelectorAll(".product"));
productsRy.forEach((p1,i1)=>{p1.style.top = i1 * (3 + 1) * 16 +"px";})
})
})
.products-container{position:relative;}
.product{
position:absolute;
padding:1em;
margin:.5em;
height:3em;
outline:1px solid; width:200px;
height:auto;
transition: all 1s;
}
}
<div class="products-container" id="container">
<div class="product" data-id-product="a" data-id-product-attribute="a">
product a
</div>
<div class="product" data-id-product="b" data-id-product-attribute="b">
product b
</div>
<div class="product" data-id-product="c" data-id-product-attribute="c">
product c
</div>
</div>
CSS really doesn't have the ability to modify an object in the same manner as JavaScript. you can do this easily.
$(".product").fadeTo("slow", 0.00, function(){
$(this).slideUp("slow", function() {
$(this).remove();
});
});
I am trying to use, and then change, the left property value of my left-hand sidebar as though it were a memory variable unsuccessfully.
My basic algorithm is
left = (left * (-1) - 250)
Initial value of left is 0.
step #1: If left (value) is 0; then left should become -250.
step #2: If left (new value) is -250; left should then become 0.
step #3: go to step #1
Try this in a spreadsheet where left is the value of the preceding row. Your result rows should look like this:
-250
0
-250
I am effectively trying to toggle the left value from 0 to -250 then back to 0.
So that my left hand sidebar is either "on" or "off" canvas as determined by the left: value.
I have tried many variations of calc, including
#leftr: 0; is set at the beginning of of my CSS sheet.
#negtv: -1; also set at the beginning of my CSS sheet.
....
#leftr: -webkit-calc(~"((#leftr * #negtv) - 250)"); /* slide-in/out 0 or -250 */
left: #leftr;
I hope this is clearer than mud and that you guys can help me?
Thanks in advance
That is not possible with pure CSS, AFAIK.
Consider to use JavaScript for that. Here's example:
Script
$('.sidebar-toggle').click(function() {
var sidebar = $('.items');
sidebar.css('margin-left', 0);
if (!sidebar.hasClass('hidden'))
sidebar.addClass('hidden');
else
sidebar.removeClass('hidden');
});
$('.sidebar-slide').click(function() {
var sidebar = $('.items');
var hidden = sidebar.hasClass('hidden');
if (hidden) {
sidebar.css('margin-left', -sidebar.width()*2);
sidebar.removeClass('hidden');
sidebar.animate({'margin-left': 0});
} else {
sidebar.css('margin-left', 0);
sidebar.removeClass('hidden');
sidebar.animate({'margin-left': -sidebar.width()*2}, function() {
sidebar.addClass('hidden');
});
}
});
HTML/CSS
<style>
.nav {
}
.nav a {
cursor: pointer;
color: navy;
font-weight: bold;
}
.items {
position: absolute;
width: 100px;
border: 1px solid black;
}
.items.hidden {
display: none;
}
</style>
<div class="nav">
Sidebar:
<a class="sidebar-toggle">Toggle</a>
| <a class="sidebar-slide">Slide</a>
</div>
<br />
<div class="items">
<div class="item">item</div>
<div class="item">item</div>
<div class="item">item</div>
<div class="item">item</div>
<div class="item">item</div>
<div class="item">item</div>
<div class="item">item</div>
</div>
You can try it at jsFiddle.
If you want a sidebar that shows up when the user clicks something, without JavaScript, you can use the hidden checkbox trick.
.sidebar {
padding:8px;
position:absolute;
left:-250px; top:0;
width:234px; height:100%;
height:calc(100% - 16px); /* sorry */
background:#CCF;
transition:left 1s;
}
#showsidebar {display:none}
label[for='showsidebar'] { /* make it look like a link */
color:blue;
text-decoration:underline;
cursor:pointer;
}
#showsidebar:checked ~ .sidebar {
left:0;
}
<input type="checkbox" id="showsidebar">
<label for="showsidebar">show sidebar</label>
<section class="sidebar">
<label for="showsidebar">hide sidebar</label>
<h1>The sidebar!</h1>
<p>(contents of sidebar)</p>
</section>
<h1>The main site</h1>
<p>Blabla. Something Latin.</p>
I have this little CSS3 animation going on in my webapp, its a panel in the bottom left side of the screen. I use Linux so I can't try out the animations in Safari, however my project leader is of course a Mac user and he complained right away it didn't work.
So, here are my two files. I'll paste everything in here that I'm working on, and in the bottom I have a jsfiddle that tried to reproduce it with plain css and fewer HTML tags. :)
Here's the less file.
.panel {
position:absolute;
left:20px;
bottom:20px;
background-image : url("./images/filter_bg.png");
width:476px;
height:126px;
z-index:1;
cursor:pointer;
}
.filter {
position:relative;
float:left;
z-index: 2;
width:119px;
height:119px;
vertical-align:24px;
overflow:hidden;
&.activeLive {
background-image: url("./images/filter_active1.png");
}
&.activeSee {
background-image: url("./images/filter_active2.png");
}
&.activeEat {
background-image: url("./images/filter_active3.png");
}
&.activeDo {
background-image: url("./images/filter_active4.png");
}
}
.filter:hover > .filter-hover {
position:absolute;
height:34px;
width:119px;
-moz-transition:-moz-transform 180ms;
-webkit-transition:-webkit-transform 180ms;
-o-transition:-o-transform 180ms;
transition:transform 180ms;
background-image:url("./images/filter_hoverlabel_bg.png");
}
.filter:hover > .filter-hover {
transform: translate(0,-24px);
}
.filter-hover{
position: relative;
bottom:-26px;
text-align:center;
line-height: 32px;
}
.filter-icon{
width:68px;
height:68px;
margin: 24px auto auto;
&.inactive1{
background-image:url("./images/filter_icon1_inactive.png");
}
&.inactive2{
background-image:url("./images/filter_icon2_inactive.png");
}
&.inactive3{
background-image:url("./images/filter_icon3_inactive.png");
}
&.inactive4{
background-image:url("./images/filter_icon4_inactive.png");
}
&.active1{
background-image:url("./images/filter_icon1_active.png");
}
&.active2{
background-image:url("./images/filter_icon2_active.png");
}
&.active3{
background-image:url("./images/filter_icon3_active.png");
}
&.active4{
background-image:url("./images/filter_icon4_active.png");
}
}
.filter-text{
text-align:center;
}
It adds a class to the divs when clicked upon, I use angular for this. So don't care to much about that.
<div class="panel" ng-controller="PanelCtrl">
<div class="{{liveEnabled ? 'filter activeLive' : 'filter'}}" ng-click="liveButton()">
<div class="{{liveEnabled ? 'filter-icon active1' : 'filter-icon inactive1'}}"></div>
<div class="filter-hover">
Bo
</div>
</div>
<div class="{{seeEnabled ? 'filter activeSee' : 'filter'}}" ng-click="seeButton()">
<div class="{{seeEnabled ? 'filter-icon active2' : 'filter-icon inactive2'}}"></div>
<div class="filter-hover">
<span class="filter-text">Se</span>
</div>
</div>
<div class="{{eatEnabled ? 'filter activeEat' : 'filter'}}" ng-click="eatButton()">
<div class="{{eatEnabled ? 'filter-icon active3' : 'filter-icon inactive3'}}"></div>
<div class="filter-hover">
<span class="filter-text">Äta</span>
</div>
</div>
<div class="{{doEnabled ? 'filter activeDo' : 'filter'}}" ng-click="doButton()">
<div class="{{doEnabled ? 'filter-icon active4' : 'filter-icon inactive4'}}"></div>
<div class="filter-hover">
<span class="filter-text">Göra</span>
</div>
</div>
</div>
I made this fiddle: http://jsfiddle.net/j97ahnkv/ wich tries to show out what I'm trying to do.
It's not working in Safari because it still requires the -webkit prefix on transform.
You have to add it to this rule:
.filter:hover > .filter-hover {
-webkit-transform: translate(0, -24px);
transform: translate(0,-24px);
}