Question

for a projekt i want to have a shake effect for a image.

HTML

<div class="col-lg-4 col-md-4 col-sm-4 sales"><img title="product" alt="product" src="layout/icommerce/img/sale6.png" /></div>

jquery

$(".sales img").toggle("shake", {direction: "left",times: 4,distance: 1}, "slow");

after loading the page, the img is shaking, but at the end of the effect, the img goes to display:none by using style="display:none"

I don´t want that.

Was it helpful?

Solution

Because you use toggle(). Use effect(...) instead:

$(".sales img").effect("shake", {
     direction: "left",
     times: 4,
     distance: 1
}, "slow");

From the jQuery UI documentation:

Toggle

Display or hide elements using custom effects.

So, because your element was visible, after toggling it it becomes invisible (display: none).

OTHER TIPS

so add a callback parameter

$(".sales img").toggle("shake", {direction: "left",times: 4,distance: 1}, "slow",function(){
  $(this).css("display","block");
});

or setup whatever you like

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top