Scrolling Cart Script for a particular catalog item

Cupcake
Mega Guru

Hi am trying this script for my catalog item that I got from the user community and I keep getting an error. Can someone take a look please?

Here is the link where I got the code from: Scrolling Cart for Service Request - Oslova Networks

find_real_file.png

Thank you,

Karen

18 REPLIES 18

Thank you David,


        Getting closer. 1 minor issue. still getting the message that e is already defined. I even tried commenting it out that didn't work.



find_real_file.png


var adder;


var adderFound = 'false';


var cartContent;


var cartContentFound = 'false';




function onLoad()


{




      adder = gel('adder');


      if (adder)


      {


              adder.style.position = "relative";


              adderFound = 'true';


      }




      cartContent = gel('sc_cart_contents');


      if (cartContent)


      {


              cartContent.style.position = "relative";


              cartContentFound = 'true';


      }




      window.onscroll = function()


      {


              var y = 12;




              if (typeof window.pageYOffset != 'undefined')


                      y = window.pageYOffset;


              else if (typeof document.documentElement.scrollTop != 'undefined' && document.documentElement.scrollTop > 0)


                      y = document.documentElement.scrollTop;


              else if (typeof document.body.scrollTop != 'undefined')


                      y = document.body.scrollTop;




              if (y > 60)


              {


                      if (adderFound == 'true')


                              adder.style.top = y - 60 + 'px';




                      if (cartContentFound == 'true')


                              cartContent.style.top = y - 60 + 'px';


              }


              else


              {


                      if (adderFound == 'true')


                              adder.style.top = 0 + 'px';




                      if (cartContentFound == 'true')


                              cartContent.style.top = 0 + 'px';


              }


      }


}


















Thank you David for the correcting the code. This is most helpful.


No more errors, but when I tried it out the "Order Now" button is NOT scrolling when the cart scrolls.



find_real_file.png


Re-examining my code, you may wish to make:


var adder;


var adderFound = 'false';


var cartContent;


var cartContentFound = 'false';



function onLoad()


{


        adder = gel('adder');




Into:


var adder;


var cartContent;


function onLoad()


{


      var adderFound = 'false';


      var cartContentFound = 'false';


      adder = gel('adder');


Now, to address the "already defined" issue in the catch statements, you can use the first piece of code I gave you and change all your catch(e) lines to catch(e1), catch(e2), catch(e3), etc...   giving each catch parameter it's own namespace.   This is a known issue with JavaScript's try/catch, as noted here:   http://stackoverflow.com/questions/6100230/javascript-catch-parameter-already-defined