Results 1 to 5 of 5

Thread: jQuery Scroll to Top Control -- Validation Error

  1. #1
    Join Date
    Jul 2012
    Posts
    76
    Thanks
    90
    Thanked 0 Times in 0 Posts

    Default jQuery Scroll to Top Control -- Validation Error

    1) Script Title: jQuery Scroll to Top Control

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex3/scrolltop.htm

    3) Describe problem: Once again, I come back for advice and assistance. I have some very long web pages and (following the advice from the Nielsen Norman Group website) I am experimenting with a table of contents for long pages, with in-page links. The Nielsen Norman guys also recommend using a persistent Back to Top button, so I added the jQuery Scroll to Top Control script from Dynamic Drive. I fiddled around with the script, changing the style of the back button to make it consistent with the rest of the site and having the back button bring you back to the table of contents instead of the start of the page.

    The page I am experimenting with is here: http://wildadirondacks.org/adirondac...argenteus.html

    Here are my questions:

    1. When I validate the page with the W3C Validator, I get the following error message: "The text content of element script was not in the required format: Expected asterisk or slash but found w instead [html5]."
    2. When I tried checking out my revised script code in various online validators, I got dozens of errors. Did I somehow accidentally mess up the code when I revised it for my purposes? If not, should I just ignore those validators, which I suspect might not always be accurate?
    3. Does putting a sticky back to top button on pages like this make sense and (if so) should the back button take you to the table of contents (from whence you came) or to the top of the page?


    Please help!

    Ellen

    Here is my revised script file:

    Code:
    //** jQuery Scroll to Top Control script- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com.
    //** Available/ usage terms at http://www.dynamicdrive.com (March 30th, 09')
    //** v1.1 (April 7th, 09'):
    //** 1) Adds ability to scroll to an absolute position (from top of page) or specific element on the page instead.
    //** 2) Fixes scroll animation not working in Opera. 
    
    
    var scrolltotop={
    	//startline: Integer. Number of pixels from top of doc scrollbar is scrolled before showing control
    	//scrollto: Keyword (Integer, or "Scroll_to_Element_ID"). How far to scroll document up when control is clicked on (0=top).
    	setting: {startline:100, scrollto: "contents", scrollduration:1000, fadeduration:[500, 100]},
    	controlHTML: '<img src="images/Scroll-to-Top.png" style="width:28px; height:28px" />', //HTML for control, which is auto wrapped in DIV w/ ID="contents"
    	controlattrs: {offsetx:5, offsety:5}, //offset of control relative to right/ bottom of window corner
    	anchorkeyword: '#contents', //Enter href value of HTML anchors on the page that should also act as "Scroll Up" links
    
    	state: {isvisible:false, shouldvisible:false},
    
    	scrollup:function(){
    		if (!this.cssfixedsupport) //if control is positioned using JavaScript
    			this.$control.css({opacity:0}) //hide control immediately after clicking it
    		var dest=isNaN(this.setting.scrollto)? this.setting.scrollto : parseInt(this.setting.scrollto)
    		if (typeof dest=="string" && jQuery('#'+dest).length==1) //check element set by string exists
    			dest=jQuery('#'+dest).offset().top
    		else
    			dest=0
    		this.$body.animate({scrollTop: dest}, this.setting.scrollduration);
    	},
    
    	keepfixed:function(){
    		var $window=jQuery(window)
    		var controlx=$window.scrollLeft() + $window.width() - this.$control.width() - this.controlattrs.offsetx
    		var controly=$window.scrollTop() + $window.height() - this.$control.height() - this.controlattrs.offsety
    		this.$control.css({left:controlx+'px', top:controly+'px'})
    	},
    
    	togglecontrol:function(){
    		var scrolltop=jQuery(window).scrollTop()
    		if (!this.cssfixedsupport)
    			this.keepfixed()
    		this.state.shouldvisible=(scrolltop>=this.setting.startline)? true : false
    		if (this.state.shouldvisible && !this.state.isvisible){
    			this.$control.stop().animate({opacity:1}, this.setting.fadeduration[0])
    			this.state.isvisible=true
    		}
    		else if (this.state.shouldvisible==false && this.state.isvisible){
    			this.$control.stop().animate({opacity:0}, this.setting.fadeduration[1])
    			this.state.isvisible=false
    		}
    	},
    	
    	init:function(){
    		jQuery(document).ready(function($){
    			var mainobj=scrolltotop
    			var iebrws=document.all
    			mainobj.cssfixedsupport=!iebrws || iebrws && document.compatMode=="CSS1Compat" && window.XMLHttpRequest //not IE or IE7+ browsers in standards mode
    			mainobj.$body=(window.opera)? (document.compatMode=="CSS1Compat"? $('html') : $('body')) : $('html,body')
    			mainobj.$control=$('<div id="topcontrol">'+mainobj.controlHTML+'</div>')
    				.css({position:mainobj.cssfixedsupport? 'fixed' : 'absolute', bottom:mainobj.controlattrs.offsety, right:mainobj.controlattrs.offsetx, opacity:0, cursor:'pointer'})
    				.attr({title:'Scroll Back to Top'})
    				.click(function(){mainobj.scrollup(); return false})
    				.appendTo('body')
    			if (document.all && !window.XMLHttpRequest && mainobj.$control.text()!='') //loose check for IE6 and below, plus whether control contains any text
    				mainobj.$control.css({width:mainobj.$control.width()}) //IE6- seems to require an explicit width on a DIV containing text
    			mainobj.togglecontrol()
    			$('a[href="' + mainobj.anchorkeyword +'"]').click(function(){
    				mainobj.scrollup()
    				return false
    			})
    			$(window).bind('scroll resize', function(e){
    				mainobj.togglecontrol()
    			})
    		})
    	}
    }
    
    scrolltotop.init()
    Here is the relevant HTML code for the Table of Contents:

    HTML Code:
    	    <div class="tableofcontents" id="contents"><a href="#description">Description</a> | <a href="#diet">Diet</a> | <a href="#reproduction">Reproduction</a> | <a href="#behavior">Behavior</a> | <a href="#predators">Mortality</a> | <a href="#distribution">Distribution</a> | <a href="#habitat">Habitat</a> | <a href="#where">Where to See </a> | <a href="#references">References</a></div>

  2. #2
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    Hello Ellen,
    Just use the W3C Validator. Ignore the others. The sticky back to top button is a good idea.

    As for the errors found by the W3C Validator:
    I. The text content of element script was not in the required format
    Reason: the presence of the keep-this-notice-intact-lines. Replace with:
    Code:
    <!--
    Scroll To Top Control script- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
    *Please keep this notice intact
    *Visit Project Page at http://www.dynamicdrive.com for full source code
    -->
    <script src="scrolltopcontrol.js"></script>
    II. Attribute webkitallowfullscreen not allowed on element iframe at this point
    Reason: the presence of webkitallowfullscreen and mozallowfullscreen. This 'error' is innocent.

    III. The type attribute is unnecessary for JavaScript resources
    Reason: the presence of type="text/javascript". Just remove it.

    IV. Attribute alt not allowed on element button at this point
    Just remove the alt-attribute. The title-attribute will do.

    That said, your code looks good to me.

  3. The Following User Says Thank You to molendijk For This Useful Post:

    ellenjones6 (04-04-2019)

  4. #3
    Join Date
    Jul 2012
    Posts
    76
    Thanks
    90
    Thanked 0 Times in 0 Posts

    Default jQuery Scroll to Top Control -- Validation Error

    Quote Originally Posted by molendijk View Post
    Hello Ellen,
    Just use the W3C Validator. Ignore the others. The sticky back to top button is a good idea.

    As for the errors found by the W3C Validator:
    I. The text content of element script was not in the required format
    Reason: the presence of the keep-this-notice-intact-lines. Replace with:
    Code:
    <!--
    Scroll To Top Control script- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
    *Please keep this notice intact
    *Visit Project Page at http://www.dynamicdrive.com for full source code
    -->
    <script src="scrolltopcontrol.js"></script>
    II. Attribute webkitallowfullscreen not allowed on element iframe at this point
    Reason: the presence of webkitallowfullscreen and mozallowfullscreen. This 'error' is innocent.

    III. The type attribute is unnecessary for JavaScript resources
    Reason: the presence of type="text/javascript". Just remove it.

    IV. Attribute alt not allowed on element button at this point
    Just remove the alt-attribute. The title-attribute will do.

    That said, your code looks good to me.
    Hi Arie,

    Thank you very much! I made the suggested changes, revalidated in the W3C Validator, and most of the errors went away. The two innocent errors (webkitallowfullscreen and mozallowfullscreen) persist, but (as you advised) I am going to ignore them. However, "The text content of element script was not in the required format" still remains. See https://validator.w3.org/nu/?doc=htt...argenteus.html

    I tried to cut and paste your suggested new code into my page, but I seem to have messed it up somehow.

    What am I doing wrong? Please advise.

    Thanks again for your help, ellen

  5. #4
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    What you have now is:
    Code:
    <script src="scrolltopcontrol.js">
    
    <!--
    Scroll To Top Control script- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
    *Please keep this notice intact
    *Visit Project Page at http://www.dynamicdrive.com for full source code
    -->
    <script src="scrolltopcontrol.js"></script>
    That should be:
    Code:
    <!--
    Scroll To Top Control script- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
    *Please keep this notice intact
    *Visit Project Page at http://www.dynamicdrive.com for full source code
    -->
    <script src="scrolltopcontrol.js"></script>

  6. The Following User Says Thank You to molendijk For This Useful Post:

    ellenjones6 (04-05-2019)

  7. #5
    Join Date
    Jul 2012
    Posts
    76
    Thanks
    90
    Thanked 0 Times in 0 Posts

    Default jQuery Scroll to Top Control -- Validation Error

    Ah, that fixed it!! Thank you!

Similar Threads

  1. Minor issue with jQuery Scroll to Top Control v1.1
    By M.D. Roche in forum Dynamic Drive scripts help
    Replies: 5
    Last Post: 04-28-2015, 02:29 AM
  2. jquery scroll to top control
    By ozetigerman in forum Dynamic Drive scripts help
    Replies: 11
    Last Post: 09-06-2014, 03:15 PM
  3. jQuery Scroll to Top Control for custom links
    By sylver in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 02-16-2012, 08:12 AM
  4. jQuery Scroll to Top Control
    By pookeyblow in forum Dynamic Drive scripts help
    Replies: 10
    Last Post: 09-17-2011, 07:13 AM
  5. jQuery Scroll to Top Control v1.1 Error
    By quddusaliquddus in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 06-30-2009, 05:13 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •