例如筋斗云的效果,但不通过offset定位的flag标记
效果:mouseenter到li上出现背景图片,mouseleave后背景图片消失,click以后该背景图片被锁定
问题:简单的mouseenter,mouseleave和click事件不能达到预期的效果,因为当click事件结束后,同时也会触发mouseleave事件
解决方案:我们给每一个li一遍循环,给li动态添加flag属性,默认值为true,是这样的我们判断当flag为false给该li设置背景图片,为true给清空;所以当mouseenter的时候,给移入的li设置背景图片;当鼠标点击li的时候给li的flag设置为取反,而其余兄弟li的flag均赋予true的属性,给点击的li设置背景图片;最后通过判断flag来决定是否触发mouseleave事件,循环遍历li,如果li的flag为true的背景图片清空
代码示例,不完全针对这个,有html结构的差别
$(function () {
$li = $(".gywm-content .content-main-left li");
$($li[0]).find("a")
.css({
"background": "url('image/guanyuwomen_anniu_xuanzhogn.png')"
, "color": " #ff2826"
});
$li.each(function (index, ele) {
ele.flag = true;
})
$li.mouseenter(function () {
$li.index = $(".gywm-content .content-main-left li").index($(this));
$(this).find("a").css({
"background": "url('image/guanyuwomen_anniu_xuanzhogn.png')"
, "color": " #ff2826"
});
});
$li.click(function () {
$(this).siblings().each(function (index, ele) {
ele.flag = true;
});
this.flag = !this.flag;
$li.index = $(".gywm-content .content-main-left li").index($(this));
$(".gywm-content .content-main-right li").removeClass("show");
$(".gywm-content .content-main-right li").eq($li.index).addClass("show");
$(this).find("a").css({
"background": "url('image/guanyuwomen_anniu_xuanzhogn.png')"
, "color": " #ff2826"
});
})
$li.mouseleave(function () {
$li.each(function (index, ele) {
if (ele.flag) {
$(ele).find("a")
.css({
"background": ""
, "color": " #333333"
});
}
})
});
})
例如筋斗云的效果,但不通过offset定位的flag标记的更多相关文章
- Vue 事件监听实现导航栏吸顶效果(页面滚动后定位)
Vue 事件监听实现导航栏吸顶效果(页面滚动后定位) Howie126313 关注 2017.11.19 15:05* 字数 100 阅读 3154评论 0喜欢 0 所说的吸顶效果就是在页面没有滑动之 ...
- Bootstrap导航点击菜单跳转与点击缩放菜单折叠按钮缓冲效果插件jquery.singlePageNav.min.js
引入步骤: <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></scrip ...
- jQuery实现 图片的局部放大效果
<html xmlns="http://www.w3.org/1999/xhtml"><head> <title></title> ...
- Android之仿ele地图定位效果
PS:最近项目要求,希望在选择地址的时候能够仿ele来实现定位效果.因此就去做了一下.不过ele使用高德地图实现的,我是用百度地图实现的.没办法,公司说用百度那就用百度的吧.个人觉得高德应该更加的精准 ...
- HTML标签marquee实现滚动效果
html标签 - <marquee></marquee>可以实现多种滚动效果,无需js控制.使用marquee标记不仅可以移动文字,也可以移动图片,表格等.只需要在<ma ...
- marquee标签实现页面内容的滚动效果
页面的自动滚动效果,可由javascript来实现, 但是有一个html标签 - <marquee></marquee>可以实现多种滚动效果,无需js控制. 使用marquee ...
- html的<marquee></marquee>标签实现滚动效果
页面的自动滚动效果,可由javascript来实现,但是今天无意中发现了一个html标签 - <marquee></marquee>可以实现多种滚动效果,无需js控制. 使用m ...
- 数的n次方 s.match(reg) marquee滚动效果
一.数的n次方 <script> alert(math.pow(a,5)); /*输出a的5次方*/ </script> 二. s.match(reg); s代表一个字符串,r ...
- JavaScript Table行定位效果
作者:cloudgamer 时间: 2009-09-17 文档类型:原创 来自:蓝色理想 第 1 页 JavaScript Table行定位效果 [1] 第 2 页 JavaScript Table行 ...
随机推荐
- 【安装Redis】CentOS7 下安装NodeJs+Express+MongoDB+Redis
Redis,V3.2,官网l官方链接:http://www.redis.io/download,参考:http://blog.csdn.net/mlks_2008/article/details/19 ...
- xml in SQL
几年前,学习html时,顺便把xml也学了哈,知道了xpath和xquery的概念,可都没去落实,下面这篇文章,可以学习学习 http://www.cnblogs.com/huyong/archive ...
- android初级篇之apk签名key keystore格式转pk8+x509.pem
转自:http://www.jianshu.com/p/3bd5c68cc44d 常用的android的签名工具有两个即jarsigner 和apksigner.这两种使用的key格式不一样,keys ...
- UVA 10692 Huge Mods(指数循环节)
指数循环节,由于a ^x = a ^(x % m + phi(m)) (mod m)仅在x >= phi(m)时成立,故应注意要判断 //by:Gavin http://www.cnblogs. ...
- SSH ProxyCommand
简单的说就是SSH层面的代理服务器,实现通过跳板机执行SSH相关命令到目标机器的代理服务.
- Linux 使用Crontab设置定时调用Shell文件
定时执行步骤: 利用crontab来定时执行任务大致有如下两步: 1.编写shell脚本 2.利用crontab加入到定时任务队列 一.如何建立shell脚本 程序必须以下面的行开始(必须方在文件的第 ...
- PyQt5+Python3.5.2-32bit开发环境搭建
1.基本环境. Window 8.1 64bit Python3.5.2-32bit.exe PyQt5 2.安装python. 去官网下载32位版本的python3.5.2(就是x86那个) 备 ...
- C#运算符号
double x=5.1e3;// 5.1乘以10 的3次方. x就是 5100 //注 : 5.1e+3=5.1e3=5.1e03=5.1e+03 double y=5.1e-3;// 5.1乘以 ...
- SQL 谜题(父亲的邮票)
问题:父亲需要些1分,2分,3分,5分,10分的邮票, 其中两种各买四张,另外的三种各买三张 我忘记是哪几种了?他给了我一些10分硬币,金额刚好买这些邮票 计算及分析过程: --通过极限算法,若都是3 ...
- 进击的Python【第十七章】:jQuery的基本应用
进击的Python[第十七章]:jQuery的基本应用