Jumping pictures using jQuery

I would like to create a bouncing effect for some images on my website.

http://jsfiddle.net/d7UjD/43/

$('#bbb').mouseenter(function() {
    $(this).stop().effect('bounce',500);
});
$('#bbb').mouseleave(function() {
    $(this).stop(true,true);
});
$('#target').mouseenter(function() {
    $(this).stop().effect('bounce',500);
});
$('#target').mouseleave(function() {
    $(this).stop(true,true);
});
$('#sears').mouseenter(function() {
    $(this).stop().effect('bounce',500);
});
$('#sears').mouseleave(function() {
    $(this).stop(true,true);
});
<div id="RegStores">
    <a href="http://www.bedbathandbeyond.com/regGiftRegistry.asp?wrn=-1824276933&amp;" target="_new"><img src="http://www.dkg2012.com/img/bbb.png" id="bbb" width="144" height="48" border="0" /></a>
    <a href="http://www.target.com/RegistryGiftGiverCmd?isPreview=false&amp;status=completePageLink&amp;listId=HCoY5fRCrcOOxRCdNn3i6g&amp;registryType=WD&amp;isAjax=false" target="_new"><img src="http://www.dkg2012.com/img/target.png" id="target" width="143" height="34" border="0" style="padding-left: 10px; padding-bottom: 5px;" /></a>
    <a href="http://www.sears.com/shc/s/GRManageView?storeId=10153&amp;catalogId=12605&amp;langId=&amp;externalId=900040792636010101&amp;grUserType=BUYER&amp;fwdURL=GRGuestRegistryView&amp;sortType=category" target="_new"><img src="http://www.dkg2012.com/img/sears.png" width="142" height="40" border="0" id="sears" style="padding-left: 10px;" /></a>
</div>
#RegStores {
    position:absolute;
    bottom:10px;
    left:23px;
    width:467px;
    height:50px;
    z-index:30;
}

Is there a way to implement this without causing the other images to shift downward? Also, when quickly moving the mouse over an image, it causes the image to continuously move upwards - any suggestions on how to resolve this?

Answer №1

In my previous response, I mentioned that the animation involves adding display: block. It actually wraps the item to animate in a div instead of directly adding the display property. To address this issue, you can use

.ui-effects-wrap { display: inline-block; }
:

http://jsfiddle.net/d7UjD/46/

Keep in mind that this solution may only function correctly in browsers that support it, so utilizing floats as an alternative might be necessary. It's advisable to apply a more specific rule (e.g., wrapping everything in its own div) to avoid affecting other effects using the same class. Ideally, there should be a way in jQuery to modify the wrapper class as well.

UPDATE: In response to feedback from Good Guy Greg about not addressing all parts of the question, I have made further improvements here:

http://jsfiddle.net/d7UjD/47/

This update prevents the image from animating on hover while already in motion. While this approach works best for me personally, if you wish to halt the animation on mouse out or initiate it again on mouseover (which seems counterintuitive to me), different steps would need to be taken.

Answer №2

One solution has been implemented to improve the functionality of driving it to the top. This involves animating it back down to its original position on mouse out. Additional enhancements have also been made, such as switching to hover and adding a class to each link instead of using separate event binders for each.

http://jsfiddle.net/EcN2h/2/

$('.bounce').hover(function() {
    $('img', this).stop(true, true).effect('bounce', 500);
}, function() {
    $('img', this).stop(true, true) );
});
​

Answer №3

Here is a helpful tip that I thought would be better suited in this section rather than a comment.

$('#bbb,#target,#sears').on('mouseenter', function() {
    $(this).stop().effect('bounce', 500);
});
$('#bbb,#target,#sears').on('mouseleave', function() {
    $(this).stop(true, true);
});

You can make your code more concise with this approach.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Vue.js: click event does not trigger transform animation

I am facing a challenge with rotating an arrow icon within a dropdown menu. Despite my efforts, the rotation does not synchronize with the appearance of the dropdown menu. Here is the Vue component code snippet: <nav> <section class= ...

Is there a way to verify that input is not empty upon loading?

Here is some code I am working with: <div><input type="text" value=""></div> Could someone please help me figure out how to use JS or jQuery to check if the input has any data (including local storage or browser cache) on load, and then ...

Adjusting the arrangement of div elements based on screen dimensions or orientation within an Ionic grid system

My HTML setup looks like this: <div class="row"> <div class="col-sm-12 col-md-6 col-xl-3"> </div> <div class="col-sm-12 col-md-6 col-xl-3"> </div> <div class="col-sm-12 col-md-6 col-xl-3"> </d ...

Creating void placeholders in a repeated loop

Suppose we have the data array stored in "$my_array". Below is an example of the expected output based on this data. Please note that due to restrictions, I am unable to modify the way data is inserted into the database. Hence, I need to create empty colu ...

What is the most effective way to implement a CSS stylesheet on a particular individual element?

Just starting out in web development and I recently experimented with a CSS stylesheet on a basic HTML element. It worked great when I targeted the element by name like this: label { color: green; } However, I wondered if there was a way to apply sty ...

Troubleshooting Bootstrap's Horizontal Alignment Problem

https://i.sstatic.net/3OTLd.pngWhile working on my Spring Boot Web App, I encountered a slight alignment issue on the login page. The problem, as shown in the attached image, is that the div is not perfectly centered on the page. I am utilizing Bootstrap f ...

Eliminate :hover effects from the :after elements' content

I am trying to eliminate the hover effect from the content inserted using the css selector :after. Below is my code where I want to remove the underline hover effect from > HTML <ul class="path_string_ul"> <li>Home</li> <l ...

Having trouble adjusting the width of the text input in the inline search box form with an input group dropdown

Looking to create a search box similar to this design: https://i.sstatic.net/H93WQ.png What is the most effective way to implement this using Bootstrap? I tried using an inline form and input group dropdown list, but I encountered issues with the text i ...

What is the best way to incorporate a scroll bar into a table that updates dynamically?

If I were to create an empty table in my index.html: <body> <table width="800" border="0" class="my-table"> <tr> </tr> </table> </body> Afterward, I would dynamically add rows and columns to my-table using ...

Adjust the button's width as the text changes to create a dynamic animation

I'm trying to create an animation effect where the width of a button changes whenever the text inside it is updated. I've attempted using useRef on the button itself to grab its clientWidth and then applying that value to a CSS variable in order ...

Vertically align all items within the div using Bootstrap to achieve perfect centering

I've been working on centering everything within this div vertically, and I've encountered some challenges along the way. Initially, I ensured that my background view extends my container nicely across the screen. Now, I'm looking to create ...

Eliminate the text color from the navigation bar links

I have implemented a navigation bar using Bootstrap. I utilized .bg-danger to include a red background color. However, the links in the navbar are displaying blue instead of black as expected with the use of .navbar-light. How can I prevent the links from ...

A design featuring two columns and a fixed footer

I'm struggling to make my 2-column layout display properly with a footer that sticks to the bottom of the page. Despite following all the usual advice, my columns keep expanding beyond their container div, which causes the footer to get pushed off the ...

Problem with modals not triggering within the iDangero.us swiper

I am encountering an issue with the iDangerous.us Swiper where I cannot activate any events within the swiper-wrapper. I am attempting to trigger a modal on each slide but nothing is happening. Any Modal placed inside the swiper-wrapper does not work. I a ...

What is the best way to utilize jQuery toggle class for adding or removing elements?

For some reason, my code isn't working as expected even though it seems fine to me. I am new to jQuery and attempting to utilize toggleClass to show card information when the card on my page is clicked. Initially, I want the information to be hidden b ...

Enhancing fancybox with dynamic scrollbars as the window size changes

I'm currently working on a popup form that I'm displaying with Fancybox 2 by using the code below: $(link).fancybox({ type: 'iFrame', autoSize: false, autoScale: false, width: '1280px', height: '1024p ...

Emphasize x-axis heading in a Highcharts graph

In my Highcharts bar graph, I am looking for a way to dynamically highlight the x-axis label of a specific bar based on an external event trigger. This event is not a standard click interaction within the Highcharts graph. Currently, I have been able to r ...

Building an array in PHP and retrieving values in JavaScript/jQuery: Tips for success

After retrieving a single record from a database query and storing it in an array: $arr = array(); while ($rowSearchZipCode = mysqli_fetch_array($resultSearchZipCode, MYSQLI_ASSOC)) { $arr[] = $rowSearchZipCode; } I am then sending this array back to ...

MUI provides the flexibility to adjust the opacity separately for Chip labels/icons and backgrounds

My objective is to customize the opacity of label/icon and background in MUI Chip. I want the label & icon to have an opacity of 1, while the background should have an opacity of 0.0571. Technologies used in this project include React, TypeScript, Materia ...

Making absolute positioning responsive in Bootstrap 4 - a comprehensive guide

I am looking to enhance the responsiveness of my page, especially on smaller screens. Currently, I have not utilized bootstrap for this purpose. I am contemplating whether I should use it or not. Can I utilize bootstrap for absolute positioning? Thank yo ...