首页 > 解决方案 > How to remove JQuery scrolltop function from a specific page

问题描述

Basically, I have a navbar which changes the logo image from transparent to full colour on scroll.

I don't want this to happen on a certain page, for example, my search results page (/toursearch).

This is the JQuery I am using below.

if (windowWidth > 991) {
    $(window).scroll(function () {
        if ($(this).scrollTop() > 50) {
            $('.logo-desk a img').attr('src', '/Includes/images/logo/holts-logo-fill.png');
        }
        if ($(this).scrollTop() <= 0) {
            $('.logo-desk a img').attr('src', '/Includes/images/logo/holts-logo-trans.png');
        }
    });
}

Any suggestions would be great.

Many thanks in advance!

标签: jquery

解决方案


脚本.js

var check = $("[disbled-scrollFun=true]");
if (!check) {
    function scrollFun() {
        if (windowWidth > 991) {
            $(window).scroll(function() {
                if ($(this).scrollTop() > 50) {
                    $('.logo-desk a img').attr('src', '/Includes/images/logo/holts-logo-fill.png');
                }
                if ($(this).scrollTop() <= 0) {
                    $('.logo-desk a img').attr('src', '/Includes/images/logo/holts-logo-trans.png');
                }
            });
        }
    }
}

任何.html

添加到正文或任何标签

<body disbled-scrollFun="true">

</body>

推荐阅读