Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Javascript and function initiating

Posted on 2010-11-21
Medium Priority
Last Modified: 2012-05-10
I have multilple js files loading into my webpage... they all worki fine together but as soon as i add this to run first it stops the others working....

Attached is the entire code... im a complete beginner when it comes to javascript... is there any reason why this would stop the others working!?


var ddpowerzoomer={
      dsetting: {defaultpower:2, powerrange:[2,7], magnifiersize:[75, 75]},
      mousewheelevt: (/Firefox/i.test(navigator.userAgent))? "DOMMouseScroll" : "mousewheel", //FF doesn't recognize mousewheel as of FF3.x
      $magnifier: {outer:null, inner:null, image:null},
      activeimage: null,

      movemagnifier:function(e, moveBol, zoomdir){
            var activeimage=ddpowerzoomer.activeimage //get image mouse is currently over
            var coords=activeimginfo.coords //get offset coordinates of image relative to upper left corner of page
            var $magnifier=ddpowerzoomer.$magnifier
            var magdimensions=activeimginfo.magdimensions //get dimensions of magnifier
            var power=activeimginfo.power.current
            var powerrange=activeimginfo.power.range
            var x=e.pageX-coords.left //get x coords of mouse within image (where top corner of image is 0)
            if (moveBol==true){
                  if (e.pageX>=coords.left && e.pageX<=coords.right && e.pageY> && e.pageY<=coords.bottom)  //if mouse is within currently within boundaries of active base image
                        $magnifier.outer.css({left:e.pageX-magdimensions[0]/2, top:e.pageY-magdimensions[1]/2})      //move magnifier so it follows the cursor
                  else{ //if mouse is outside base image
                        $magnifier.outer.hide() //hide magnifier
            else if (zoomdir){ //if zoom in
                  var od=activeimginfo.dimensions //get dimensions of image
                  var newpower=(zoomdir=="in")? Math.min(power+1, powerrange[1]) : Math.max(power-1, powerrange[0]) //get new power from zooming in or out
                  var nd=[od[0]*newpower, od[1]*newpower] //calculate dimensions of new enlarged image within magnifier
                  $magnifier.image.css({width:nd[0], height:nd[1]})
                  activeimginfo.power.current=newpower //set current power to new power after magnification
            power=activeimginfo.power.current //get current power
            var newx=-x*power+magdimensions[0]/2 //calculate x coord to move enlarged image
            var newy=-y*power+magdimensions[1]/2
            $magnifier.inner.css({left:newx, top:newy}) //move image wrapper within magnifier so the correct image area is shown

      setupimage:function($, imgref, options){
            var s=jQuery.extend({}, ddpowerzoomer.dsetting, options)
            var $imgref=$(imgref)
  { //create object to remember various info regarding image
                  power: {current:s.defaultpower, range:s.powerrange},
                  magdimensions: s.magnifiersize,
                  dimensions: [$imgref.width(), $imgref.height()],
                  coords: null
            $imgref.unbind('mouseenter').mouseenter(function(e){ //mouseenter event over base image
                  var $magnifier=ddpowerzoomer.$magnifier
                  $magnifier.outer.css({width:s.magnifiersize[0], height:s.magnifiersize[1]}) //set magnifier's size
                  var offset=$imgref.offset() //get image offset from document
                  $magnifier.inner.html('<img src="'+options.largeimagesrc+'"/>') //get base image's src and create new image inside magnifier based on it
                        .css({[0]*power,[1]*power}) //set size of enlarged image
                  var coords={left:offset.left,,[0],[1]}
         //remember left, right, and bottom right coordinates of image relative to doc

            var $magnifier=$('<div style="position:absolute;width:100px;height:100px;display:none;overflow:hidden;border:1px solid black;" />')
                  .append('<div style="position:relative;left:0;top:0;" />')
                  .appendTo(document.body) //create magnifier container and add to doc
            ddpowerzoomer.$magnifier={outer:$magnifier, inner:$magnifier.find('div:eq(0)'), image:null} //reference and remember various parts of magnifier
            $(document).unbind('mousemove.trackmagnifier').bind('mousemove.trackmagnifier', function(e){ //bind mousemove event to doc
                  if (ddpowerzoomer.activeimage){ //if mouse is currently over a magnifying image
                        ddpowerzoomer.movemagnifier(e, true) //move magnifier
            }) //end document.mousemove

            $magnifier.outer.bind(ddpowerzoomer.mousewheelevt, function(e){ //bind mousewheel event to magnifier
                  if (ddpowerzoomer.activeimage){
                        var delta=e.detail? e.detail*(-120) : e.wheelDelta //delta returns +120 when wheel is scrolled up, -120 when scrolled down
                        if (delta<=-120){ //zoom out
                              ddpowerzoomer.movemagnifier(e, false, "out")
                        else{ //zoom in
                              ddpowerzoomer.movemagnifier(e, false, "in")
} //ddpowerzoomer

      var $=jQuery
      return this.each(function(){ //return jQuery obj
            if (this.tagName!="IMG")
                  return true //skip to next matched element
            if (typeof options=="undefined")
            if (options.largeimage && options.largeimage.length>0){ //preload large image?
                  options.preloadimg=new Image()
            var $imgref=$(this)
            options.largeimagesrc=(options.preloadimg)? options.preloadimg.src : $imgref.attr('src')
            if (parseInt(>0 && parseInt(>0) //if image has explicit CSS width/height defined
                  ddpowerzoomer.setupimage($, this, options)
            else if (this.complete){ //account for IE not firing image.onload
                  ddpowerzoomer.setupimage($, this, options)
                  $imgref.bind('load', function(){
                        ddpowerzoomer.setupimage($, this, options)

jQuery(document).ready(function($){ //initialize power zoomer on DOM load
Question by:maccaj51
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Author Comment

ID: 34183112
<script type="text/javascript">

jQuery(document).ready(function($){ //fire on DOM ready


this has to be in the head section... seems to be playing a role!!!!
LVL 22

Accepted Solution

remorina earned 2000 total points
ID: 34185111
The code you are using seems to be jQuery while you are using jQuery.noConflict(); before it.

the jQuery.noConflict(); should only be used before JavaScript that isn't jQuery so it wouldn't conflict with the $ Selector.

try removing the jQuery.noConflict(); at the top and see if this makes it work, also using a console debugger like FireFox firebug add-on might help you figure out what is causing the error.

LVL 16

Expert Comment

by:Justin Mathews
ID: 34189636
Can you post the code for the rest of the page?

Author Closing Comment

ID: 34291531
worked for me!

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question