我刚刚在我目前工作的一家由WooCommerce驱动的商店上实现了smoothState.js。可以通过以下链接找到现场演示:http://demos.oosh.co/bt
我唯一的问题是两个:
能不能找个更能胜任这个助手的人?
顺便提一下,这是我用来调用smoothState.js的代码。我从Envato在这个链接https://webdesign.tutsplus.com/tutorials/how-to-integrate-smoothstatejs-into-a-wordpress-theme--cms-26610上的图斯普鲁斯教程中获得了这段代码。
// Using smoothstate-js to Ajax-load pages
(function($) {
function addBlacklistClass() {
$('a').each( function() {
if (this.href.indexOf('/wp-admin/') !== -1 ||
this.href.indexOf('/wp-login.php') !== -1) {
$(this).addClass('wp-link');
}
});
}
$(function() {
addBlacklistClass();
var settings = {
anchors: 'a',
blacklist: '.wp-link',
onStart: {
duration: 320,
render: function ($container) {
$container.addClass('slide-out');
}
},
onAfter: function($container) {
addBlacklistClass();
var $hash = $(window.location.hash);
if ($hash.length !== 0) {
var offsetTop = $hash.offset().top;
$('body, html').animate({
scrollTop: (offsetTop - 60),
}, {
duration: 320
} );
}
$container.removeClass('slide-out');
}
};
$('#app').smoothState(settings);
});
})(jQuery); // End smoothstate-js谢谢你的帮助。
发布于 2017-01-15 18:04:45
我给黑名单函数增加了几行代码,这似乎解决了这个问题。不过,我会继续调查,以确保一切正常。现在,除了你想破坏我的密码,我觉得我很好。
(function($) {
function addBlacklistClass() {
$('a').each( function() {
if (this.href.indexOf('/wp-admin/') !== -1 ||
this.href.indexOf('/wp-login.php') !== -1 ||
this.href.indexOf('/?add-to-cart') !== -1 ||
this.href.indexOf('?remove_item') !== -1) {
$(this).addClass('no-smoothState');
}
});
$('input[type="submit"]').each(function() {
$(this).addClass('no-smoothState');
});
}
$(function() {
addBlacklistClass();
var settings = {
anchors: 'a',
forms: 'input',
blacklist: '.no-smoothState',
onStart: {
duration: 320,
render: function ($container) {
$container.addClass('slide-out');
}
},
onAfter: function($container) {
addBlacklistClass();
var $hash = $(window.location.hash);
if ($hash.length !== 0) {
var offsetTop = $hash.offset().top;
$('body, html').animate({
scrollTop: (offsetTop - 60),
}, {
duration: 320
} );
}
$container.removeClass('slide-out');
}
};
$('#app').smoothState(settings);
});
})(jQuery);https://stackoverflow.com/questions/41649310
复制相似问题