Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Javascript 

Javascript help :c

Ye, I know I have a lots of problems, but when I finish my site, I will stop asking questions ✌

So help me please with this javascript. So, I found this javascript, which is I think very useful, but I have 1 problem with that:
It's scrolling to the section what you href, but it is scrolling the whole page.
Well, I need to use this script to scroll to the data In layer(which is has a scrollbar, thats why I need it :) )

So, is it possible to change the javascript somehow to make it work?
If yes, help me please :) 😊

Here is the script
PHP Code

<?php 
var bookmarkscroll={
    
setting: {duration:1000, yoffset:0}, //{duration_of_scroll_milliseconds, offset_from_target_element_to_rest}
    
topkeyword: '#top', //keyword used in your anchors and scrollTo() to cause script to scroll page to very top

    
scrollTo:function(dest, options, hash){
        var $=
jQuery, options=options || {}
        var 
$dest=(typeof dest=="string" && dest.length>0)? (dest==this.topkeyword? 0 : $('#'+dest)) : (dest)? $(dest) : [] //get element based on id, topkeyword, or dom ref
        
if ($dest===0 || $dest.length==1 && (!options.autorun || options.autorun && Math.abs($dest.offset().top+(options.yoffset||this.setting.yoffset)-$(window).scrollTop())>5)){
            
this.$body.animate({scrollTop: ($dest===0)? 0 : $dest.offset().top+(options.yoffset||this.setting.yoffset)}, (options.duration||this.setting.duration), function(){
                if (
$dest!==0 && hash)
                    
location.hash=hash
            
})
        }
    },

    
urlparamselect:function(){
        var 
param=window.location.search.match(/scrollto=[\w\-_,]+/i) //search for scrollto=divid
        
return (param)? param[0].split('=')[1] : null
    
},
    
    
init:function(){
        
jQuery(document).ready(function($){
            var 
mainobj=bookmarkscroll
            mainobj
.$body=(window.opera)? (document.compatMode=="CSS1Compat"? $('html') : $('body')) : $('html,body')
            var 
urlselectid=mainobj.urlparamselect() //get div of page.htm?scrollto=divid
            
if (urlselectid) //if id defined
                
setTimeout(function(){mainobj.scrollTo(document.getElementById(urlselectid) || $('a[name='+urlselectid+']:eq(0)').get(0), {autorun:true})}, 100)
            $(
'a[href^="#"]').each(function(){ //loop through links with "#" prefix
                
var hashvalue=this.getAttribute('href').match(/#\w+$/i) //filter links at least 1 character following "#" prefix
                
hashvalue=(hashvalue)? hashvalue[0].substring(1) : null //strip "#" from hashvalue
                
if (this.hash.length>1){ //if hash value is more than just "#"
                    
var $bookmark=$('a[name='+this.hash.substr(1)+']:eq(0)')
                    if (
$bookmark.length==1 || this.hash==mainobj.topkeyword){ //if HTML anchor with given ID exists or href==topkeyword
                        
if ($bookmark.length==1 && !document.all) //non IE, or IE7+
                            
$bookmark.html('.').css({position:'absolute', fontSize:1, visibility:'hidden'})
                        $(
this).click(function(e){
                            
mainobj.scrollTo((this.hash==mainobj.topkeyword)? mainobj.topkeyword : $bookmark.get(0), {}, this.hash)
                            
e.preventDefault()
                        })
                    }
                }
            })
        })
    }
}

bookmarkscroll.init() 

If you can help, please help, I really need it 🤩

Thanks,
Hotmailkukac 🤝
Do you want the scroll automated?
(May 25, 2010 08:07 PM)mastrmind Wrote:  I think you are asking for some script ,which will scroll to a specific location in page ,when we click on some anchor tag.
If thats what you want you can use
Code
<a href="#middle">scroll</a>
When someone clicks this "scroll" then he/she will be taken to the location of page where this div is
Code
<div id="middle">hi</div>
The whole script is about that :D
But I don't need to scroll in the whole page, I need that scrip to scroll in the Layer, what has fixed height, but the data in that is much longer, so there is a scrollbar.
So I want to scrolll in that layer :P
(May 25, 2010 08:32 PM)Xon Wrote:  Do you want the scroll automated?
No, I want to scroll if they click :P

Thanks :)
Hotmailkukac
Make a div that you put all the data in and make it auto scroll and then only call that function for that certain div


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Javascript]  by flexing_99Apr 29, 2023 12:02 AM 3 269 Apr 29, 2023 12:02 AM
Last Post: Zgh600
[Javascript]  by FacewipeSep 7, 2021 03:44 AM 1 177 Sep 7, 2021 03:44 AM
Last Post: kitkatas
[Javascript]  by Button5Aug 8, 2021 07:32 AM 1 329 Aug 8, 2021 07:32 AM
Last Post: MavenGradle