JQuery------实现点击左右按钮,切换图片功能
如图:

代码:
html
@*商品主图片*@
<div class="product-img" style="display:table-cell;width:400px;border:1px solid #aaa;text-align:center">
<img width="500" height="400" src="/upload/store/@ViewBag.StoreId/product/show/thumb350_350/@ViewBag.ProductImg"/>
</div> @*商品所有图片*@
<div class="product-img-all" style="margin-top:15px;width:400px">
<div class="product-img-prev" style="float:left;width:30px;height:62px;text-align:center;line-height:62px;color:#fff;font-size:25px;background- color:#ccc"><</div>
<ul style="display:inline-block;height:60px">
@foreach (ProductImage item in ViewBag.ProductImages)
{
<li name ="list" style="display:inline-block;border:1px solid #bce8f1">
<img src="/upload/store/@ViewBag.StoreId/product/show/thumb60_60/@item.showimg" />
<input type="hidden" value="@item.showimg"/>
</li>
}
</ul>
<div class="product-img-next" style="float:right;width:30px;height:62px;text-align:center;line-height:62px;color:#fff;font-size:25px;background -color:#ccc">></div>
</div>
js
$(document).ready(function () {
//商品主图边框为深色
$(".product-img-all").find("li").eq(0).css({ "border": "1px solid #6581ee" });
//商品所有图片点击事件
$(".product-img-all").find("li").click(function () {
$(this).css({ "border": "1px solid #6581ee" });
$(this).prevAll("li").css({ "border": "1px solid #bce8f1" });
$(this).nextAll("li").css({ "border": "1px solid #bce8f1" });
var img = $(this).find("input").val();
getProductImg(img);
});
//上一张商品图
$(".product-img-prev").mousedown(function () {
$(this).css({ "backgroundColor": "#aaa" });
}).mouseup(function () {
$(this).css({ "backgroundColor": "#ccc" });
var img = $(".product-img-all").find("li");
img.each(function (index) {
var b = $(this).css("border");
//index会为0
if (b.indexOf("101, 129, 238") != -1 && index != 0) {
$(this).css({ "border": "1px solid #bce8f1" }); //浅色
$(this).prev("li").css({ "border": "1px solid #6581ee" }); //深色
var i = $(this).prev("li").find("input").val();
getProductImg(i);
}
});
});
//下一张商品图
$(".product-img-next").mousedown(function () {
$(this).css({ "backgroundColor": "#aaa" });
}).mouseup(function () {
$(this).css({ "backgroundColor": "#ccc" });
var img = $(".product-img-all").find("li");
img.each(function (index) {
//index从0开始
if ((index + 1) == img.length) {
return false;
};
var b = $(this).css("border");
//index会为0
if (b.indexOf("101, 129, 238") != -1) {
$(this).css({ "border": "1px solid #bce8f1" }); //浅色
$(this).next("li").css({ "border": "1px solid #6581ee" }); //深色
var i = $(this).next("li").find("input").val();
getProductImg(i);
return false; //跳出遍历
}
});
});
});
//设置商品大图
function getProductImg(img) {
$(".product-img").find("img").attr("src", "/upload/store/" + getParameter("storeId") + "/product/show/thumb350_350/" + img);
}
//获取Url地址中的参数
function getParameter(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
JQuery------实现点击左右按钮,切换图片功能的更多相关文章
- JQuery实现点击按钮切换图片(附源码)--JQuery基础
JQuery实现切换图片相对比较简单,直接贴代码了哈,有注释噢!疑问请追加评论哈,不足之处还请大佬们指出! 1.案例代码: demo.html: <!DOCTYPE html><ht ...
- 用 JS 点击左右按钮 使图片切换 - 最精简版-ljx2380000-ChinaUnix博客
body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI ...
- 使用jQuery实现点击左右滑动切换特效
使用jQuery实现点击左右滑动切换特效: HTML代码如下: <!--整体背景div--> <div class="warp"> <!--中间内容d ...
- jQuery实现的鼠标滑过切换图片代码实例
jQuery实现的鼠标滑过切换图片代码实例:有时候网页需要这样的简单效果,那就是当鼠标滑过默认图片的时候,能够实现图片的切换,可能在实际应用中,往往没有这么简单,不过大家可以自行扩展一下,下面简单介绍 ...
- JQuery移动动画实现点击按钮切换图片--JQuery基础
直接贴源码了哈,这些都是自己总结的……汗水几何?希望能帮到大家. <%@ Page Language="C#" AutoEventWireup="true" ...
- 原生js点击按钮切换图片
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- 炫酷实用的jQuery插件 涵盖菜单、按钮、图片
新的一周开始了,今天我们要为大家分享一些全新的jQuery插件和HTML5/CSS3应用,这些jQuery插件不仅非常炫酷,而且还挺实用,这次的分享包含jQuery菜单.CSS3按钮已经多种图片特效, ...
- Axure初体验:简单交互、通过按钮切换图片
前言: 之前是一直用processon的UI原型设计,后来感觉只能完成静态页面的processon满足不了原型设计的需求,断网时候也不方便修改.展示.最终还是决定学习动态页面的制作,所选工具为原型设计 ...
- jQuery演示10种不同的切换图片列表动画效果
经常用到的图片插件演示jQuery十种不同的切换图片列表动画效果 在线演示 下载地址 实例代码 <!DOCTYPE html> <html lang="en" c ...
- jQuery演示10种不同的切换图片列表动画效果以及tab动画演示 2
很常用的一款特效纯CSS完成tab实现5种不同切换对应内容效果 实例预览 下载地址 实例代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ...
随机推荐
- cocos2d-x 源代码分析 : EventDispatcher、EventListener、Event 源代码分析 (新触摸机制,新的NotificationCenter机制)
源代码版本号来自3.x,转载请注明 cocos2d-x 源代码分析总文件夹 http://blog.csdn.net/u011225840/article/details/31743129 1.继承结 ...
- Spring @Autowired、@Resource、@Required、@Component、@Repository、@Service、@Controller注解的用法和作用
Spring @Autowired,@Resource,@Required注解的用法和作用 Spring中 @Autowired标签与 @Resource标签 的区别 Spring注解@Compone ...
- 不经意的小错误——onclick和click的区别
可能注意不到的错误,编写jquery时发现没有自己想要的效果,结果通过代码比对软件才发现原来将click写成了onclick,虽然看着差不多,但意义却不相同,简单区别如下: $().click() 是 ...
- MySQL-安全对调两个表名
我们想要的是同时完成表名对调,如果是先后的对掉,用RENAME的话可能会导致有些数据写入失败,那怎么办? 其实也不难,从MySQL手册里就能找到方法,那就是:同时锁定2个表,不允许写入,然后对调表名. ...
- 列举一些常见的系统系能瓶颈 Common Bottlenecks
http://www.nowamagic.net/librarys/veda/detail/2408在 Zen And The Art Of Scaling - A Koan And Epigram ...
- Spring boot配置fastjson
pom 文件引用 <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson< ...
- 【python下使用OpenCV实现计算机视觉读书笔记1】输入输出
说明: 该部分内容为<OpenCV Computer Vision with Python>读书笔记. 1.读入文件与保存. import cv2 image=cv2.imread('a. ...
- java开发中国际化
1 静态文本的国际化,就是比如页面中中文显示用户名就是用户名,用于显示就是 username. 其中静态文件命名遵循:基础名_语言简称_国家简称.properties 需要使用的类是 1)import ...
- shell脚本分析 nginx日志访问次数最多及最耗时的页面
当服务器压力比较大,跑起来很费力时候.我们经常做站点页面优化,会去查找那些页面访问次数比较多,而且比较费时. 找到那些访问次数高,并且比较耗时的地址,就行相关优化,会取得立竿见影的效果的. 下面是我在 ...
- [svc]influxdb+grafana实战-各省份api访问成功率统计
简单说下需求: 统计各个省份的 3大运营商的接口访问成功率,绘图展示 数据格式 {"mobile" : "15812345608", "provinc ...