Brugernavn:




Kodeord: Husk
Forside Forum Artikler Downloads Søg
 

Jquery hjælp

Hej alle sammen, sidder lige og bikser med et script jeg faldt over.. rimelig fed måde at vise billeder på synes jeg selv.
den centrer og "zoomer" ind på et givent billede:
koden her
  • <img src="Billede" class="magnify" data-magnifyby="2.5"  alt="Reference" border="0">

mit spørgsmål er så, om der er nogle der ved hvordan jeg får vist f.eks. billede 1: men det den faktisk skal vise er billede 2 ?

den bruger blandt andet denne fil:

http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
og
dette stykke kode:
  1. /* jQuery Image Magnify script v1.1
  2. * This notice must stay intact for usage
  3. * Author: Dynamic Drive at http://www.dynamicdrive.com/
  4. * Visit http://www.dynamicdrive.com/ for full source code

  5. * Nov 16th, 09 (v1.1): Adds ability to dynamically apply/reapply magnify effect to an image, plus magnify to a specific width in pixels.
  6. */

  7. jQuery.noConflict()

  8. jQuery.imageMagnify={
  9.     dsettings: {
  10.         magnifyby: 3, //default increase factor of enlarged image
  11.         duration: 500, //default duration of animation, in millisec
  12.         imgopacity: 0.2 //opacify of original image when enlarged image overlays it
  13.      },
  14.     cursorcss: 'url(magnify.cur), -moz-zoom-in', //Value for CSS's 'cursor' attribute, added to original image
  15.     zIndexcounter: 100,

  16.     refreshoffsets:function($window, $target, warpshell){
  17.         var $offsets=$target.offset()
  18.         var winattrs={x:$window.scrollLeft(), y:$window.scrollTop(), w:$window.width(), h:$window.height()}
  19.         warpshell.attrs.x=$offsets.left //update x position of original image relative to page
  20.         warpshell.attrs.y=$offsets.top
  21.         warpshell.newattrs.x=winattrs.x+winattrs.w/2-warpshell.newattrs.w/2
  22.         warpshell.newattrs.y=winattrs.y+winattrs.h/2-warpshell.newattrs.h/2
  23.         if (warpshell.newattrs.x<winattrs.x+5){ //no space to the left?
  24.             warpshell.newattrs.x=winattrs.x+5    
  25.         }
  26.         else if (warpshell.newattrs.x+warpshell.newattrs.w > winattrs.x+winattrs.w){//no space to the right?
  27.             warpshell.newattrs.x=winattrs.x+5
  28.         }
  29.         if (warpshell.newattrs.y<winattrs.y+5){ //no space at the top?
  30.             warpshell.newattrs.y=winattrs.y+5
  31.         }
  32.     },

  33.     magnify:function($, $target, options){
  34.         var setting={} //create blank object to store combined settings
  35.         var setting=jQuery.extend(setting, this.dsettings, options)
  36.         var attrs=(options.thumbdimensions)? {w:options.thumbdimensions[0], h:options.thumbdimensions[1]} : {w:$target.outerWidth(), h:$target.outerHeight()}
  37.         var newattrs={}
  38.         newattrs.w=(setting.magnifyto)? setting.magnifyto : Math.round(attrs.w*setting.magnifyby)
  39.         newattrs.h=(setting.magnifyto)? Math.round(attrs.h*newattrs.w/attrs.w) : Math.round(attrs.h*setting.magnifyby)
  40.         $target.css('cursor', jQuery.imageMagnify.cursorcss)
  41.         if ($target.data('imgshell')){
  42.             $target.data('imgshell').$clone.remove()
  43.             $target.css({opacity:1}).unbind('click.magnify')
  44.         }    
  45.         var $clone=$target.clone().css({position:'absolute', left:0, top:0, visibility:'hidden', border:'1px solid gray', cursor:'pointer'}).appendTo(document.body)
  46.         $clone.data('$relatedtarget', $target) //save $target image this enlarged image is associated with
  47.         $target.data('imgshell', {$clone:$clone, attrs:attrs, newattrs:newattrs})
  48.         $target.bind('click.magnify', function(e){ //action when original image is clicked on
  49.             var $this=$(this).css({opacity:setting.imgopacity})
  50.             var imageinfo=$this.data('imgshell')
  51.             jQuery.imageMagnify.refreshoffsets($(window), $this, imageinfo) //refresh offset positions of original and warped images
  52.             var $clone=imageinfo.$clone
  53.             $clone.stop().css({zIndex:++jQuery.imageMagnify.zIndexcounter, left:imageinfo.attrs.x, top:imageinfo.attrs.y, width:imageinfo.attrs.w, height:imageinfo.attrs.h, opacity:0, visibility:'visible'})
  54.             .animate({opacity:1, left:imageinfo.newattrs.x, top:imageinfo.newattrs.y, width:imageinfo.newattrs.w, height:imageinfo.newattrs.h}, setting.duration,
  55.             function(){ //callback function after warping is complete
  56.                 //none added        
  57.             }) //end animate
  58.         }) //end click
  59.         $clone.click(function(e){ //action when magnified image is clicked on
  60.             var $this=$(this)
  61.             var imageinfo=$this.data('$relatedtarget').data('imgshell')
  62.             jQuery.imageMagnify.refreshoffsets($(window), $this.data('$relatedtarget'), imageinfo) //refresh offset positions of original and warped images
  63.             $this.stop().animate({opacity:0, left:imageinfo.attrs.x, top:imageinfo.attrs.y, width:imageinfo.attrs.w, height:imageinfo.attrs.h},  setting.duration,
  64.             function(){
  65.                 $this.hide()
  66.                 $this.data('$relatedtarget').css({opacity:1}) //reveal original image
  67.             }) //end animate
  68.         }) //end click
  69.     }
  70. };

  71. jQuery.fn.imageMagnify=function(options){
  72.     var $=jQuery
  73.     return this.each(function(){ //return jQuery obj
  74.         var $imgref=$(this)
  75.         if (this.tagName!="IMG")
  76.             return true //skip to next matched element
  77.         if (parseInt($imgref.css('width'))>0 && parseInt($imgref.css('height'))>0 || options.thumbdimensions){ //if image has explicit width/height attrs defined
  78.             jQuery.imageMagnify.magnify($, $imgref, options)
  79.         }
  80.         else if (this.complete){ //account for IE not firing image.onload
  81.             jQuery.imageMagnify.magnify($, $imgref, options)
  82.         }
  83.         else{
  84.             $(this).bind('load', function(){
  85.                 jQuery.imageMagnify.magnify($, $imgref, options)
  86.             })
  87.         }
  88.     })
  89. };

  90. jQuery.fn.applyMagnifier=function(options){ //dynamic version of imageMagnify() to apply magnify effect to an image dynamically
  91.     var $=jQuery
  92.     return this.each(function(){ //return jQuery obj
  93.         var $imgref=$(this)
  94.         if (this.tagName!="IMG")
  95.             return true //skip to next matched element
  96.         
  97.     })    

  98. };


  99. //** The following applies the magnify effect to images with class="magnify" and optional "data-magnifyby" and "data-magnifyduration" attrs
  100. //** It also looks for links with attr rel="magnify[targetimageid]" and makes them togglers for that image

  101. jQuery(document).ready(function($){
  102.     var $targets=$('.magnify')
  103.     $targets.each(function(i){
  104.         var $target=$(this)
  105.         var options={}
  106.         if ($target.attr('data-magnifyto'))
  107.             options.magnifyto=parseFloat($target.attr('data-magnifyto'))
  108.         if ($target.attr('data-magnifyby'))
  109.             options.magnifyby=parseFloat($target.attr('data-magnifyby'))
  110.         if ($target.attr('data-magnifyduration'))
  111.             options.duration=parseInt($target.attr('data-magnifyduration'))
  112.         $target.imageMagnify(options)
  113.     })
  114.     var $triggers=$('a[rel^="magnify["]')
  115.     $triggers.each(function(i){
  116.         var $trigger=$(this)
  117.         var targetid=$trigger.attr('rel').match(/\[.+\]/)[0].replace(/[\[\]']/g, '') //parse 'id' from rel='magnify[id]'
  118.         $trigger.data('magnifyimageid', targetid)
  119.         $trigger.click(function(e){
  120.             $('#'+$(this).data('magnifyimageid')).trigger('click.magnify')
  121.             e.preventDefault()
  122.         })
  123.     })
  124. })

Pointfordeling

Forfatteren har lukket tråden og har valgt at fordele de 88 point således:
serverin 88 point
Oprettet af:

Javascript

Point afsat: 88

Lukket
22:47 13/05/2010
lukker tråden
Oprettet af:

Accepteret svar

Point modtaget: 88
11:10 07/07/2010
Du skal være oprettet og logget ind for at svare på en tråd
Copyright © Rowl.dk v/ Michael Raagaard | 2005-12 | Alle rettigheder forbeholdes