0

I'd like this piece of javascript to change only on hover instead of making it a permanent background.

<script type="text/javascript">
$(function () {
    $('ul.slideshow-menu').find('a').fadeTo('slow', 1);
    $('ul.slideshow-menu').find('a').hover(function () {
        $(this).fadeTo('fast', 1);
        $('.pikachoose').css({
            'background-image': 'url(' + $(this).attr('src') + ')'
        });
    }, function () {
        $(this).fadeTo('slow', 1);
    });
});
</script>

Right now it looks for an image i set in my "a href" tag and it takes this url to the class ".pikachoose" and replaces its background image. I want it to do this only on HOVER and when nothing is hovered it changes back to the original background-image.

Anyone got any ideas?

0

4 Answers 4

1

In your second function simply set the pikachoose css back to the original url lile so :

$('ul.slideshow-menu').find('a').hover(function(){
  $(this).fadeTo('fast', 1);
  $('.pikachoose').css({ 'background-image' : 'url('+$(this).attr('src')+')' });
}, function(){
$(this).fadeTo('slow', 1);
$('.pikachoose').css({ 'background-image' : 'url(youroriginalurl)' });
});
Sign up to request clarification or add additional context in comments.

Comments

0
$('.pikachoose').css({ 'background-image' : 'url(/'+$(this).attr('src')+')' });

Comments

0

it should look like this :

$(function(){
        ('ul.slideshow-menu').find('a').hover(function(){
        $('.pikachoose').css({'background-image':'url(/'+$(this).attr('src')+')' });
        });

Comments

0

Try this

 $(document).ready(function () {
        $(".a").on("mouseover", function () { this.style.backgroundImage = url('new image url'); });
        $(".a").on("mouseout", function () { this.style.backgroundImage = url('default image url'); });
    });

HTML

 <div class="a" style="width: 100px; border: 1px solid black;">
    Hello, i am div1
</div>
<div class="a" style="width: 100px; border: 1px solid black;">
    Hiii i am div2
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.