Results 1 to 5 of 5

Thread: Drop in once per session

  1. #1
    Join Date
    Jun 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Drop in once per session

    I'm having real issues solving this one, (although I admit to knowing absolutely nothing about javascript).

    I love the drop in style of thefollowing script:

    Code:
    <script language="JavaScript1.2">
    
    // Drop-in content box- By Dynamic Drive
    // For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
    // This credit MUST stay intact for use
    
    var ie=document.all
    var dom=document.getElementById
    var ns4=document.layers
    var calunits=document.layers? "" : "px"
    
    var bouncelimit=32 //(must be divisible by 8)
    var direction="up"
    
    function initbox(){
    if (!dom&&!ie&&!ns4)
    return
    crossobj=(dom)?document.getElementById("dropin").style : ie? document.all.dropin : document.dropin
    scroll_top=(ie)? truebody().scrollTop : window.pageYOffset
    crossobj.top=scroll_top-250+calunits
    crossobj.visibility=(dom||ie)? "visible" : "show"
    dropstart=setInterval("dropin()",50)
    }
    
    function dropin(){
    scroll_top=(ie)? truebody().scrollTop : window.pageYOffset
    if (parseInt(crossobj.top)<100+scroll_top)
    crossobj.top=parseInt(crossobj.top)+40+calunits
    else{
    clearInterval(dropstart)
    bouncestart=setInterval("bouncein()",50)
    }
    }
    
    function bouncein(){
    crossobj.top=parseInt(crossobj.top)-bouncelimit+calunits
    if (bouncelimit<0)
    bouncelimit+=8
    bouncelimit=bouncelimit*-1
    if (bouncelimit==0){
    clearInterval(bouncestart)
    }
    }
    
    function dismissbox(){
    if (window.bouncestart) clearInterval(bouncestart)
    crossobj.visibility="hidden"
    }
    
    function truebody(){
    return (document.compatMode!="BackCompat")? document.documentElement : document.body
    }
    
    
    window.onload=initbox
    
    </script>
    Problem is, I need it to only display once per session.

    I found the followng script that only displays once per session, which is very good but it doesn't bounce in:


    Code:
    <script>
    
    //Post-it only once per browser session? (0=no, 1=yes)
    //Specifying 0 will cause postit to display every time page is loaded
    var once_per_browser=1
    
    ///No need to edit beyond here///
    
    var ns4=document.layers
    var ie4=document.all
    var ns6=document.getElementById&&!document.all
    
    if (ns4)
    crossobj=document.layers.postit
    else if (ie4||ns6)
    crossobj=ns6? document.getElementById("postit") : document.all.postit
    
    
    function closeit(){
    if (ie4||ns6)
    crossobj.style.visibility="hidden"
    else if (ns4)
    crossobj.visibility="hide"
    }
    
    function get_cookie(Name) {
      var search = Name + "="
      var returnvalue = "";
      if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        if (offset != -1) { // if cookie exists
          offset += search.length
          // set index of beginning of value
          end = document.cookie.indexOf(";", offset);
          // set index of end of cookie value
          if (end == -1)
             end = document.cookie.length;
          returnvalue=unescape(document.cookie.substring(offset, end))
          }
       }
      return returnvalue;
    }
    
    function showornot(){
    if (get_cookie('postdisplay')==''){
    showit()
    document.cookie="postdisplay=yes"
    }
    }
    
    function showit(){
    if (ie4||ns6)
    crossobj.style.visibility="visible"
    else if (ns4)
    crossobj.visibility="show"
    }
    
    if (once_per_browser)
    showornot()
    else
    showit()
    
    </script>
    
    <script language="JavaScript1.2">
    
    //drag drop function for ie4+ and NS6////
    /////////////////////////////////
    
    function drag_drop(e){
    if (ie4&&dragapproved){
    crossobj.style.left=tempx+event.clientX-offsetx
    crossobj.style.top=tempy+event.clientY-offsety
    return false
    }
    else if (ns6&&dragapproved){
    crossobj.style.left=tempx+e.clientX-offsetx
    crossobj.style.top=tempy+e.clientY-offsety
    return false
    }
    }
    
    function initializedrag(e){
    if (ie4&&event.srcElement.id=="postit"||ns6&&e.target.id=="postit"){
    offsetx=ie4? event.clientX : e.clientX
    offsety=ie4? event.clientY : e.clientY
    
    tempx=parseInt(crossobj.style.left)
    tempy=parseInt(crossobj.style.top)
    
    dragapproved=true
    document.onmousemove=drag_drop
    }
    }
    document.onmousedown=initializedrag
    document.onmouseup=new Function("dragapproved=false")
    
    </script>
    I've tried merging the two scripts, but as I said above, I don't have the first clue about javascript, and what seems an obvious solution doesn't work, so must be wrong.

    Does anyone have any clues, or can point me in the right direction?

  2. #2
    Join Date
    Jun 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Surely there must be some javascript wizards out there who can tell me which bit to put where?

  3. #3
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Actually "drop in once per session" is a built in feature of "Drop In Content" script. Is there a reason why you're not just using the wizard on this page to generate the appropriate code: http://www.dynamicdrive.com/dynamici.../dropinbox.htm ?

  4. #4
    Join Date
    Jun 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ah ha! Perfect. I couldn't find the original page from where I got the script, searching didn't bring it up and I copied the code from another site where I used the drop-in box. I was desperate for it as it's a fantastic script.

    Cheers for that.

  5. #5
    Join Date
    May 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default bounce problem

    Hi. I have a script which is of the same thing but probably an earlier version.

    It allows me to bounce in on an onclick (the later version doesn't seem to let me do this.) The problem is that it won't have the bounce occurring twice without a page reload.

    Does anyone know why?

    Code:
    var calunits = "px";
    var bouncelimit = 20;   // must be divisible by 5
    var crossobj;
    var timer;
    
    function initbox(id)
    {
        crossobj = document.getElementById(id).style;
        var scroll_top = getPageY();
        crossobj.top = (scroll_top - 500) + calunits;
        crossobj.display = "";
        setTimeout("dropin()",50);
    }
    
    function dropin()
    {
        var scroll_top = getPageY();
        if (parseInt(crossobj.top) < 50 + scroll_top)
        {
            crossobj.top = (parseInt(crossobj.top) + 40) + calunits;
            setTimeout("dropin()",50);
        }
        else
        {
            timer = setInterval("bouncein()",50);
        }
    }
    
    function bouncein()
    {
        crossobj.top = (parseInt(crossobj.top) - bouncelimit) + calunits;
        if (bouncelimit < 0)
            bouncelimit += 5;
        bouncelimit = bouncelimit * -1;
        if (bouncelimit == 0)
            clearInterval(timer);
    }
    
    function getPageY()
    {
        if (window.pageYOffset)
            var scroll_top = window.pageYOffset;
        else if (document.documentElement.scrollTop)
            var scroll_top = document.documentElement.scrollTop;
        else
            var scroll_top = document.body.scrollTop;
    
        return scroll_top;
    }
    <img border="0" src="clickme.gif" onclick="initbox('dropin');">

    Thanks.

    Terry

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
  •