样式切换器单击后会跳到页面顶部
style switcher when clicked jumps to the top of the page
我有style switcher,使用php和jquery来实现它。现在,当我点击它的按钮打开时,页面会跳到页面顶部。以及当我单击相同的按钮关闭样式框时。同样的情况,它会跳到页面的顶部。如何更改代码以使其在不跳转的情况下打开。
jQuery.fn.styleSwitcher = function(){
$(this).click(function(){
// We're passing this element object through to the
// loadStyleSheet function.
loadStyleSheet(this);
// And then we're returning false.
return false;
});
function loadStyleSheet(obj) {
$.get( obj.href+'&js',function(data){
// Select link element in HEAD of document (#stylesheet) and change href attribute:
$('#stylesheet').attr('href','css/' + data + '.css');
// Check if new CSS StyleSheet has loaded:
});
}
}
$(document).ready(function () {
$(".toggleDiv .expand-arrow").show();
$(".toggleDiv .shrink-arrow").hide();
$(".toggleDiv .expand-arrow").click(function(){
$("#style-switcher").animate(
{"left": "0"}, "slow");
$("#swatchesDiv").animate(
{"opacity": "1"}, "slow");
$(".toggleDiv .expand-arrow").hide();
$(".toggleDiv .shrink-arrow").show();
});
$(".toggleDiv .shrink-arrow").click(function(){
$("#style-switcher").animate(
{"left": "-200px"}, "slow");
$("#swatchesDiv").animate(
{"opacity": "0"}, "slow");
$(".toggleDiv .expand-arrow").show();
$(".toggleDiv .shrink-arrow").hide();
});
});
您应该使用preventDefault
或return false
:禁用链接的行为
$(document).ready(function () {
$(".toggleDiv .expand-arrow").show();
$(".toggleDiv .shrink-arrow").hide();
$(".toggleDiv .expand-arrow").click(function(e){
e.preventDefault(); // disable the link
$("#style-switcher").animate(
{"left": "0"}, "slow");
$("#swatchesDiv").animate(
{"opacity": "1"}, "slow");
$(".toggleDiv .expand-arrow").hide();
$(".toggleDiv .shrink-arrow").show();
});
$(".toggleDiv .shrink-arrow").click(function(e){
e.preventDefault(); // disable the link
$("#style-switcher").animate(
{"left": "-200px"}, "slow");
$("#swatchesDiv").animate(
{"opacity": "0"}, "slow");
$(".toggleDiv .expand-arrow").show();
$(".toggleDiv .shrink-arrow").hide();
});
});
相关文章:
- 为样式表切换器存储js cookie
- 与号.js多个视图切换器
- 通过Alloy UI(Liferay 6.2)在切换器中加载视频
- 当我单击返回第一个切换时,第二个切换器应该关闭
- Javascript样式表切换器
- 使用Javascript为样式切换器添加样式表的最佳方法
- 选中取消选中切换器
- jQuery内容面板切换器阻止访问表单元素
- 在 Jquery 中为语言切换器分配一个全局变量
- UIkit:将切换器选项卡设置为当前窗口哈希
- 多语言语言切换器 asp.net
- 即时CSS样式切换器/滚轮
- 如何构建一个jQuery驱动的切换器来添加/删除css属性
- jQuery切换器需要限制所选开关的数量
- 寻找一种风格切换器
- 使用jQuery和下拉菜单的简单样式表切换器
- 我创建了一个CSS切换器,但我只需要更改class=“”的元素;红色”;身体
- jquery css样式切换器将cookie设置为css
- css+jQuery样式.css切换器,用于新的jQuery版本
- 样式切换器单击后会跳到页面顶部