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 ...
随机推荐
- linux静态链接库与动态链接库详解
一顺便说说了哦 通常情况下,对函数库的链接是放在编译时期(compile time)完成的.所有相关的对象文件(object file)与牵涉到的函数库(library)被链接合成一个可执行文件(e ...
- iDempiere VS World
怀揣着为中小企业量身定做一整套开源软件解决方案的梦想开始了一个网站的搭建.http://osssme.org/ 第四篇 iDempiere VS World 接下来就接着第一篇,再说一说iDempei ...
- `libsass` bindings not found. Try reinstalling `node-sass`?
本篇文章由:http://xinpure.com/libsass-bindings-not-found-try-reinstalling-node-sass/ 坑一记 `libsass` bindin ...
- 简述document.write和 innerHTML的区别。
document.write是重写整个document, 写入内容是字符串的htmlinnerHTML是HTMLElement的属性,是一个元素的内部html内容
- CentOS 6.3下Samba服务器的安装与配置(转)
一.简介 Samba是一个能让Linux系统应用Microsoft网络通讯协议的软件,而SMB是Server Message Block的缩写,即为服务器消息块 ,SMB主要是作为Microsoft的 ...
- Linux-软件包管理-yum在线管理-网络yum源
cd /etc/yum.repos.d/ 切换到etc目录下面的yum.repos.d这个目录中ls 查看当前linux系统的yum源文件信息,其中CentOS-Base.repo文件为默认的y ...
- winform通过网络获取用户信息
1.获取当前部署: public static NameValueCollection GetQueryStringParameters() { NameValueCollection nameVal ...
- MySQL中多表删除方法
如果您是才接触MySQL数据库的新人,那么MySQL中多表删除是您一定需要掌握的,下面就将为详细介绍MySQL中多表删除的方法,供您参考,希望对你学习掌握MySQL中多表删除能有所帮助. 1.从MyS ...
- Graphics View框架
Qt4.2开始引入了Graphics View框架用来取代Qt3中的Canvas模块,并在很多地方作了改进,Graphics View框架实现了模型-视图结构的图形管理,能对大量图元进行管理,支持碰撞 ...
- error while loading shared libraries *.so.*
转自 http://my.oschina.net/u/561492/blog/192341 ubuntu12.04-64位编译Android4.2时出现问题:error while loading s ...