/** * DOM **/ function ge() { var ea; for (var i = 0; i < arguments.length; i++) { var e = arguments[i]; if (typeof e == 'string') e = document.getElementById(e); if (arguments.length == 1) return e; if (!ea) ea = new Array(); ea.push(e); } return ea; }
function geByClass(searchClass, node, tag) { var classElements = new Array(); if ( node == null ) node = document; if ( tag == null ) tag = '*'; if (node.getElementsByClassName) { classElements = node.getElementsByClassName(searchClass); if (tag != '*') { for (i = 0; i < classElements.length; i++) { if (classElements.nodeName == tag) classElements.splice(i, 1); } } return classElements; } var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); for (i = 0, j = 0; i < elsLen; i++) { if ( pattern.test(els[i].className) ) { classElements[j] = els[i]; j++; } } return classElements; }
function show(elem) { if (arguments.length > 1) { for (var i = 0; i < arguments.length; i++) { show(arguments[i]); } return; } elem = ge(elem); if (!elem) return; var old = data(elem, "olddisplay"); elem.style.display = old || "";
function hide(elem){ if (arguments.length > 1) { for (var i = 0; i < arguments.length; i++) { hide(arguments[i]); } return; } elem = ge(elem); if (!elem) return; if (getStyle(elem, 'display') != "none") data(elem, "olddisplay", elem.style.display); elem.style.display = "none"; } function isVisible(elem) { elem = ge(elem); return getStyle(elem, 'display') != 'none' && getStyle(elem, 'visibility') != 'hidden'; } function toggle(elem) { if (isVisible(elem)) { hide(elem); } else { show(elem); } } window.shide = toggle;
function getXY(obj) { if (!obj || obj == undefined) return; var left = 0, top = 0; if (obj.offsetParent) { do { left += obj.offsetLeft; top += obj.offsetTop; } while (obj = obj.offsetParent); } return [left,top]; }
function getSize(elem, woBounds) { var s = [0, 0]; if (elem == document) { s = [Math.max( document.documentElement["clientWidth"], document.body["scrollWidth"], document.documentElement["scrollWidth"], document.body["offsetWidth"], document.documentElement["offsetWidth"] ), Math.max( document.documentElement["clientHeight"], document.body["scrollHeight"], document.documentElement["scrollHeight"], document.body["offsetHeight"], document.documentElement["offsetHeight"] )]; } else if (elem){ function getWH() { s = [elem.offsetWidth, elem.offsetHeight]; if (!woBounds) return; var padding = 0, border = 0; each(s, function(i, v) { var which = i ? ['Top', 'Bottom'] : ['Left', 'Right']; each(which, function(){ s[i] -= parseFloat(getStyle(elem, "padding" + this)) || 0; s[i] -= parseFloat(getStyle(elem, "border" + this + "Width")) || 0; }); }); s = [Math.round(s[0]), Math.round(s[1])]; } if (!isVisible(elem)) { var props = {position: "absolute", visibility: "hidden", display:"block"}; var old = {}; each(props, function(i, val){ old[i] = elem.style[i]; elem.style[i] = val; }); getWH(); each(props, function(i, val){ elem.style[i] = old[i]; }); } else getWH();
function isFunction(obj) { return Object.prototype.toString.call(obj) === "[object Function]"; }
function isArray(obj) { return Object.prototype.toString.call(obj) === "[object Array]"; }
function now() { return +new Date; }
function trim(text) { return (text || "").replace(/^\s+|\s+$/g, ""); }
/** * Arrays, objects **/
function each(object, callback) { var name, i = 0, length = object.length;
if ( length === undefined ) { for ( name in object ) if ( callback.call( object[ name ], name, object[ name ] ) === false ) break; } else for ( var value = object[0]; i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
return object; }; function indexOf(arr, value, from) { from = (from == null) ? 0 : from; var m = arr.length; for(var i = from; i < m; i++) if (arr[i] == value) return i; return -1; }
function clone(obj) { var newObj = {}; for (var i in obj) { newObj[i] = obj[i]; } return newObj; }
// Extending object by another function extend() { // copy reference to target object var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
// Handle a deep copy situation if (typeof target === "boolean") { deep = target; target = arguments[1] || {}; // skip the boolean and the target i = 2; }
// Handle case when target is a string or something (possible in deep copy) if (typeof target !== "object" && !isFunction(target)) target = {};
// return target object if only one argument is passed if (length == i) { return target; }
for (; i < length; i++) // Only deal with non-null/undefined values if ((options = arguments[i]) != null) // Extend the base object for (var name in options) { var src = target[name], copy = options[name];
// Prevent never-ending loop if (target === copy) continue;
// Recurse if we're merging object values if (deep && copy && typeof copy === "object" && !copy.nodeType) target[name] = extend(deep, // Never move original objects, clone them src || (copy.length != null ? [] : { }) , copy);
// Don't bring in undefined values else if (copy !== undefined) target[name] = copy; }
// Return the modified object return target; }
/** * CSS classes **/
function hasClass(obj, name) { return obj && (new RegExp('(\\s|^)' + name + '(\\s|$)')).test(obj.className); }
function removeClass(obj, name) { if (obj && hasClass(obj, name)) { obj.className = obj.className.replace((new RegExp('(\\s|^)' + name + '(\\s|$)')), ' '); } }
// Get computed style function getStyle(elem, name) {
if (name == "width" || name == "height") { return getSize(elem, true)[({'width':0, 'height':1})[name]] + 'px'; } var ret, defaultView = document.defaultView || window; if (defaultView.getComputedStyle) { name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase(); var computedStyle = defaultView.getComputedStyle( elem, null ); if (computedStyle) ret = computedStyle.getPropertyValue(name); } else if (elem.currentStyle) { if (name == 'opacity' && browser.msie) { var filter = elem.currentStyle['filter']; return filter && filter.indexOf("opacity=") >= 0 ? (parseFloat(filter.match(/opacity=([^)]*)/)[1] ) / 100) + '' : '1'; } var camelCase = name.replace(/\-(\w)/g, function(all, letter){ return letter.toUpperCase(); }); ret = elem.currentStyle[name] || elem.currentStyle[camelCase]; // If we're not dealing with a regular pixel number // but a number that has a weird ending, we need to convert it to pixels if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) { // Remember the original values var left = style.left, rsLeft = elem.runtimeStyle.left;
// Put in the new values to get a computed value out elem.runtimeStyle.left = elem.currentStyle.left; style.left = ret || 0; ret = style.pixelLeft + "px";
// Get or set element data function data(elem, name, data) { var id = elem[ expand ], undefined; if ( !id ) id = elem[ expand ] = ++vk_uuid;
if (name && !vk_cache[id]) vk_cache[id] = {};
if (data !== undefined) vk_cache[id][name] = data;
return name ? vk_cache[id][name] : id; }
function removeData(elem, name) { var id = elem[expand]; if (name) { if (vk_cache[id]) { delete vk_cache[id][name]; name = ""; for (name in vk_cache[id]) break;
if (!name) removeData(elem); } } else { try { delete elem[expand]; } catch(e){ // fix for IE if (elem.removeAttribute) elem.removeAttribute(expand); } delete vk_cache[id]; } }
/** * Simple FX **/ function animate(el, params, speed, callback) { el = ge(el); var options = extend({}, typeof speed == 'object' ? speed : {duration: speed, onComplete: callback || function(){}}); var tween = data(el, 'tween'); if (tween) { tween.setOptions(options); } else { tween = data(el, 'tween', new Fx.Base(el, options)); } return tween.custom(params); }
function fadeTo(el, speed, to, callback) {return animate(el, {opacity: to}, speed, callback);}
function addEvent(elem, types, handler) { if (!elem || elem.nodeType == 3 || elem.nodeType == 8 ) return;
// For whatever reason, IE has trouble passing the window object // around, causing it to be cloned in the process if (elem.setInterval && elem != window) elem = window;
var events = data(elem, "events") || data(elem, "events", []), handle = data(elem, "handle") || data(elem, "handle", function(){ _eventHandle.apply(arguments.callee.elem, arguments); }); // Add elem as a property of the handle function // This is to prevent a memory leak with non-native // event in IE. handle.elem = elem; each(types.split(/\s+/), function(index, type) { var handlers = events[type]; if (!handlers) { handlers = events[type] = new Array();
if (elem.addEventListener) elem.addEventListener(type, handle, false); else if (elem.attachEvent) elem.attachEvent('on' + type, handle); } handlers.push(handler); });
elem = null; }
function removeEvent(elem, type, handler) { if (!elem) return; var events = data(elem, "events"); if (events) { if (typeof(type) == 'string' && isArray(events[type])) { if (isFunction(handler)) { for (var i = 0; i < events[type].length; i++) { if (events[type][i] == handler) { delete events[type][i]; break; } } } else { for (var i = 0; i < events[type].length; i++) { delete events[type][i]; } } } else { for (var i in events) { removeEvent(elem, i); } return; } for (var ret in events[type]) break; if (!ret && data(elem, "handle")) {
if (elem.removeEventListener) elem.removeEventListener(type, data(elem, "handle"), false); else if (elem.detachEvent) elem.detachEvent("on" + type, data(elem, "handle")); } ret = null; delete events[type]; } }
function cancelEvent(event) { var e = event.originalEvent || event; if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); e.cancelBubble = true; e.returnValue = false; return false; }
function _eventHandle(event) { event = event || window.event;
var originalEvent = event; event = clone(originalEvent); event.originalEvent = originalEvent;
if (!event.target) event.target = event.srcElement || document;
// check if target is a textnode (safari) if ( event.target.nodeType == 3 ) event.target = event.target.parentNode;
if (!event.relatedTarget && event.fromElement) event.relatedTarget = event.fromElement == event.target
// Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs) if ( !event.metaKey && event.ctrlKey ) event.metaKey = event.ctrlKey;
// Add which for click: 1 == left; 2 == middle; 3 == right // Note: button is not normalized, so don't use it if ( !event.which && event.button ) event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) ));
var handlers = data(this, "events"); if (!handlers || typeof(event.type) != 'string' || !handlers[event.type] || !handlers[event.type].length) { return; } try {
for (var i = 0; i < handlers[event.type].length; i++) { if (event.type == 'mouseover' || event.type == 'mouseout') { var parent = event.relatedElement; // Traverse up the tree while ( parent && parent != this ) try { parent = parent.parentNode; } catch(e) { parent = this; } if (parent == this) { continue } } var ret = handlers[event.type][i].apply(this, arguments); if (ret === false) { cancelEvent(event); } } } catch (e) { var a = 0; } }
// Prevent memory leaks in IE // And prevent errors on refresh with events like mouseover in other browsers // Window isn't included so as not to unbind existing unload events addEvent(window, "unload", function(){ for (var id in vk_cache) if (vk_cache[id].handle && vk_cache[id].handle.elem != window) removeEvent(vk_cache[id].handle.elem); });
// Dom ready event handler (function(){ var isRdy = false, rdyBnd = false, rdyList = [];
case 'MESSAGE': addClass(boxContainer, 'message_box'); removeEvent(transparentBG, 'click'); break; } }
// Show box function showBox() { if (isVisible) return; isVisible = true; each(_message_boxes, function(box_guid, box) { if (box_guid != guid) box.hide(); }); // Show blocking background show(transparentBG); // Show box
// fadeIn(boxContainer, 200); show(boxContainer); // AntanubiS - Video wall posting fails with fadeIn =(
refreshCoords();
// Hide all flash movies on the page if (options.hideFlash) { clearTimeout(_show_flash_timeout); each(body.getElementsByTagName('embed'), function(i, el) { el.style.visibility = 'hidden'; }); each(body.getElementsByTagName('object'), function(i, el) { el.style.visibility = 'hidden'; }); }
if (options.onShow) { options.onShow(); } } // Hide box function hideBox(speed) { if (!isVisible) return; isVisible = false;
var onHide = function () { hide(boxContainer); hide(transparentBG); // Show all flash movies on the page if (options.hideFlash) { if (_show_flash_timeout) clearTimeout(_show_flash_timeout); _show_flash_timeout = setTimeout(function() { each(body.getElementsByTagName('embed'), function(i, el) { el.style.visibility = 'visible'; }); each(body.getElementsByTagName('object'), function(i, el) { el.style.visibility = 'visible'; }); }, 50); } if (options.onHide) options.onHide(); } if (speed > 0) { fadeOut(boxContainer, speed, function(){ onHide(); }); } else { onHide(); } }
var retBox = { guid: guid, // Show box show: function(speed) { showBox(speed); return this; },
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
Здравствуйте, подскажите какой тег использовать для увеличения значения, пример на картинке.
Вроде, про такой тег я слышала. Если есть тег прогресс бар, значит и такое должно быть.
Question
Antuan
Ниже небольшой кодик
Очень понравилась реализация просмотра изображений нас сайте Вконтакте
Решил выдернуть код от туда, получился не совсем как я ожидал. Очень длинный код
Может кто знает
как реализовать эту функцию в "несколько строк"
Link to comment
Share on other sites
16 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.