当鼠标在div上时,我使用mouseenter和mouseleave来添加和删除类。
在桌面上,它工作得很好,但我意识到在移动设备上就不行了。 当我点击链接的div时,它将类放入该链接,然后转到该链接,当我返回历史记录时,该div保留了类,因此其他div都“消失”了。
代码如下:
null
jQuery('.lg-row .lg-col .lg-placeholder').on('mouseenter', function(){
let link = jQuery(this).parent('a').attr('href');
jQuery('a[href!="'+link+'"]').children().addClass('hideImages');
});
jQuery('.lg-row .lg-col .lg-placeholder').on('mouseleave', function(){
let link = jQuery(this).parent('a').attr('href');
jQuery('a[href!="'+link+'"]').children().removeClass('hideImages');
});
null
如果你来自同一个页面,历史会返回(如果你不是,它会将你重定向到主页)
null
$('.both .old-a, #cross-single').click(function(e){
e.preventDefault();
if (document.referrer.indexOf(location.protocol + "//" + location.host) === 0) {
window.history.back()
} else {
window.location.href=$(this).attr('href');
}
})
null
以下是历史回溯后的样子:https://gyazo.com/79ad27fdc1537abefb09b6a5f32dfc2d
您的HTML中有jquery的链接和脚本吗?