新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
JS實(shí)現(xiàn)多圖點(diǎn)擊切換,鼠標(biāo)移上放大
繼 javascript 簡(jiǎn)單的圖片放大效果(一) 之后,把這個(gè)效果完善了一下,支持多圖輪流切換,如下:

創(chuàng)新互聯(lián)公司是專業(yè)的平邑網(wǎng)站建設(shè)公司,平邑接單;提供網(wǎng)站制作、網(wǎng)站建設(shè),網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行平邑網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!
本次采用代碼封裝到一個(gè)對(duì)象的模式,和***次函數(shù)式寫法不一下,這樣更清晰,添加自定義屬性更方便,全部代碼如下:
大圖的地址用自定義屬性的方式顯示在標(biāo)簽如
圖片放大實(shí)例 - * {
- margin: 0;
- padding: 0;
- }
- #zoomWarp {
- width: 1000px;
- margin: 20px auto;
- overflow: hidden;
- }
- #smallwarp {
- position: relative;
- border: 1px solid #000;
- width: 300px;
- height: 300px;
- float: left;
- overflow: hidden;
- }
- #minImg {
- float: left;
- display: inline;
- margin-right: 5px;
- }
- #minImg li {
- width: 70px;
- height: 70px;
- overflow: hidden;
- background: #ccc;
- margin-bottom: 5px;
- border: 1px solid #333;
- cursor: pointer;
- list-style: none;
- }
- #minImg li.lastChild {
- margin-bottom: 0;
- }
#p#
VVG.base庫代碼:
- /*
- * 簡(jiǎn)單JS庫封裝 By VVG
- * @namespace VVG
- * E-mail:mysheller@163.com QQ:83816819
- */
- if (!String.trim) {
- String.prototype.trim = function () {
- var reg = /^\s+|\s+$/g;
- return this.replace(reg, '');
- }
- }
- (function () {
- // create namespace VVG
- if (!window.VVG) {
- window.VVG = {};
- }
- function isCompatible(other) {
- // Use capability detection to check requirements
- if (other === false || !Array.prototype.push || !Object.hasOwnProperty || !document.createElement || !document.getElementsByTagName) {
- alert('你的瀏覽器不支持某些特性!');
- return false;
- }
- return true;
- }
- window.VVG.isCompatible = isCompatible;
- // getElementById function
- function $() {
- var elements = new Array();
- for (var i = 0; i < arguments.length; i++) {
- var element = arguments[i];
- if (typeof element == 'string') {
- element = document.getElementById(element);
- }
- if (!element) {
- continue;
- }
- // 如果只有一個(gè)參數(shù),則返回
- if (arguments.length == 1) {
- return element;
- }
- // 多個(gè)參數(shù)的時(shí)候存為數(shù)組
- elements.push(element);
- }
- // 返回?cái)?shù)組
- return elements;
- }
- window.VVG.$ = $;
- // 獲取Parent父元素下標(biāo)簽名為child 的 Tags
- function $$(tag, parent) {
- parentparent = parent || document;
- return $(parent).getElementsByTagName(tag);
- }
- window.VVG.$$ = $$;
- // getElementsByClassName
- function $$$(str, parent, tag) {
- //父節(jié)點(diǎn)存在
- if (parent) {
- parent = $(parent);
- } else {
- // 未傳值時(shí),父節(jié)點(diǎn)為body
- parent = document;
- }
- // tagContent為節(jié)點(diǎn)類型,未傳值時(shí)為all節(jié)點(diǎn)
- tagtag = tag || '*';
- // 在父節(jié)點(diǎn)查找子節(jié)點(diǎn),建立空數(shù)組arr
- var els = parent.getElementsByTagName(tag),
- arr = [];
- for (var i = 0, n = els.length; i < n; i++) {
- // 查找每個(gè)節(jié)點(diǎn)下的classname,以空格分離為一個(gè)k數(shù)組
- for (var j = 0, k = els[i].className.split(' '), l = k.length; j < 1; j++) {
- // 當(dāng)K數(shù)組中有一個(gè)值與str值相等時(shí),記住這個(gè)標(biāo)簽并推入arr數(shù)組
- if (k[j] == str) {
- arr.push(els[i]);
- break;
- }
- }
- }
- // 返回?cái)?shù)組
- return arr;
- }
- window.VVG.$$$ = $$$;
- window.VVG.getElementsByClassName = $$$;
- // Event事件綁定:綁定type事件到element元素,觸發(fā)func函數(shù)
- function bindEvent(element, type, func) {
- if (element.addEventListener) {
- element.addEventListener(type, func, false); //false 表示冒泡
- } else if (element.attachEvent) {
- element.attachEvent('on' + type, func);
- } else {
- element['on' + type] = func;
- }
- }
- window.VVG.bindEvent = bindEvent;
- // 解除Event事件綁定
- function unbindEvent(element, type, func) {
- if (element.removeEventListener) {
- element.removeEventListener(type, func, false);
- } else if (element.detachEvent) {
- element.detachEvent('on' + type, func);
- } else {
- element['on' + type] = null;
- }
- }
- window.VVG.unbindEvent = unbindEvent;
- // 獲取事件
- function getEvent(event) {
- return event || window.event;
- }
- window.VVG.getEvent = getEvent;
- // 獲取事件目標(biāo)
- function getTarget(event) {
- return event.target || event.srcElement;
- }
- window.VVG.getTarget = getTarget;
- // 獲取鼠標(biāo)位于文檔的坐標(biāo)
- function getMousePositionInPage(event) {
- event = getEvent(event);
- return {
- 'x':event.pageX || event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft),
- 'y':event.pageY || event.clientY + (document.documentElement.scrollTop || document.body.scrollTop)
- }
- }
- window.VVG.getMousePositionInPage = getMousePositionInPage;
- // 停止事件冒泡
- function stopPropagation(event) {
- if (event.stopPropagation) {
- event.stopPropagation();
- } else {
- event.cancelBubble = true;
- }
- }
- window.VVG.stopPropagation = stopPropagation;
- // 阻止默認(rèn)事件
- function preventDefault(event) {
- if (event.preventDefault) {
- event.preventDefault();
- } else {
- event.returnValue = false;
- }
- }
- window.VVG.preventDefault = preventDefault;
- // apply從新定義函數(shù)的執(zhí)行環(huán)境
- function bindFunction(obj, func) {
- return function () {
- return func.apply(obj, arguments);
- };
- }
- window.VVG.bindFunction = bindFunction;
- // 設(shè)置透明度
- function setOpacity(node, level) {
- node = $(node);
- if (document.all) {
- node.style.filter = 'alpha(opacity=' + level + ')';
- } else {
- node.style.opacity = level / 100;
- }
- }
- window.VVG.setOpacity = setOpacity;
- // 獲取可視窗口尺寸
- function getWindowSize() {
- var de = document.documentElement;
- return {
- 'width':(
- window.innerWidth || (de && de.clientWidth) || document.body.clientWidth),
- 'height':(
- window.innerHeight || (de && de.clientHeight) || document.body.clientHeight)
- }
- }
- window.VVG.getWindowSize = getWindowSize;
- // 數(shù)字轉(zhuǎn)化為千分位格式函數(shù)
- function thousandsNumberFormat(str) {
- var n = str.length;
- var c = n % 3;
- var reg = /\d{3}(?!$)/g;
- if (n > 3) {
- var strstr1 = str.slice(0, c);
- var strstr2 = str.slice(c, n);
- str1str1 = str1 ? str1 + ',' : '';
- str = str1 + str2.replace(reg, function (p1) {
- return p1 + ',';
- })
- }
- return str;
- }
- window.VVG.thousandsNumberFormat = thousandsNumberFormat;
- // 帶橫杠的字符形式轉(zhuǎn)化為駝峰式命名
- function camelize(string) {
- return string.replace(/-(\w)/g, function (strMatch, p1) {
- return p1.toUpperCase();
- });
- }
- window.VVG.camelize = camelize;
- // 駝峰式轉(zhuǎn)化為橫杠分隔
- function uncamelize(string, sep) {
- sepsep = sep || '-';
- return string.replace(/([a-z])([A-Z])/g, function (strMatch, p1, p2) {
- return p1 + sep + p2.toLowerCase();
- });
- }
- window.VVG.uncamelize = uncamelize;
- // 設(shè)置根據(jù)ID設(shè)置樣式
- function setStyleById(element, cssjson) {
- element = $(element);
- for (property in cssjson) {
- if (!cssjson.hasOwnProperty(property)) continue;
- if
網(wǎng)站名稱:JS實(shí)現(xiàn)多圖點(diǎn)擊切換,鼠標(biāo)移上放大
文章來源:http://www.5511xx.com/article/cophgcc.html


咨詢
建站咨詢
