Question

I don't know why this code is not working:

$(window).scroll(function () {
    var $scrtop = $(window).scrollTop(),
    $topnavbar = $(".topbar,.navbar-fixed-top");

    $topnavbar.mouseenter(function(){
        $topnavbar.stop(true,true).fadeTo(4000,1);
    }).mouseleave(function(){
        $topnavbar.stop(true,true).fadeTo(4000,.5);
    })
    if( $scrtop > 100 )
    {
        $topnavbar.stop(true,true).fadeTo(4000,.5);
    } else {
        $topnavbar.stop(true,true).fadeTo(4000,1);
    }

});//scroll

It just goes direct to the final opacity without the stages of the fadeTo(). Here it is in jsfiddle: http://jsfiddle.net/pPr9S/

Was it helpful?

Solution

UPDATED THE CODE

you are to remove second true from stop, because it actually finishes the next animation on the queue;

var $topnavbar = $(".topbar,.navbar-fixed-top"),  
    $scrtop;  
 $(window).scroll(function () {
$scrtop = $(window).scrollTop();
if( $scrtop > 100 )
{
    $topnavbar.stop(true).fadeTo(500,.5);
} else {
    $topnavbar.stop(true).fadeTo(500,1);
}
});

$topnavbar.hover(function(){
$topnavbar.stop(true).fadeTo(500,1);
}, function(){
    $topnavbar.stop(true).fadeTo(500,.5);
});

OTHER TIPS

I don't know what is your problem, try with this and if not, please insert html code on js http://jsfiddle.net/, so you will get your answer very quickly ...

var $topnavbar = $(".topbar,.navbar-fixed-top"),
    $scrtop; $(window).scroll(function () {
    $scrtop = $(window).scrollTop();
    if( $scrtop > 100 )
    {
        $topnavbar.stop().fadeTo(4000,.5);
    } else {
        $topnavbar.stop().fadeTo(4000,1);
    } });

$topnavbar.hover(function(){
    $topnavbar.stop().fadeTo(4000,1); }, function(){
    $topnavbar.stop().fadeTo(4000,.5); });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top