Results 1 to 4 of 4

Thread: "Stay On Top" content script - center DIV...?

  1. #1
    Join Date
    May 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question "Stay On Top" content script - center DIV...?

    1) Script Title: Stay On Top Content Script

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici.../stayontop.htm

    3) Describe problem: I'd like to have the popup DIV centered on the page rather than appear in one of the corners. DDAdmin did address this before but his modified .js file seems to be no longer available and that thread is now closed >> http://www.dynamicdrive.com/forums/s...-Script-Center

    Regards,
    Zan
    Last edited by Zanato; 04-08-2014 at 07:42 PM.

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    modified functions with changes in red

    Code:
    	init:function(options){
    		var settings={}
      	settings=jQuery.extend(settings, this.dsettings, options);
    		this.settingscache[settings.targetid]=settings
    		if (typeof settings.frequency=="number") //value of 1=show, 0=hide
    			settings.display=(settings.frequency>Math.random())? 1 : 0
    		else if (settings.frequency=="session")
    			settings.display=(this.getCookie('sots'+settings.targetid)=='shown')? 0 : 1 //session cookie name: 'sots' + targetid
    		else if (/^\d+ day/i.test(settings.frequency)){ //match 'xx days'
    			//If admin has changed number of days to persist from current cookie records, reset persistence by deleting cookie
    			if (parseInt(this.getCookie('sotp'+settings.targetid))!= parseInt(settings.frequency))
    				this.setCookie('sotp'+settings.targetid, '', -1)
    			settings.display=(this.getCookie('sotp'+settings.targetid)!=null)? 0 : 1 //persistent cookie name: 'sotp' + targetid
    		}
    		jQuery(document).ready(function($){
            if (settings.orientation==5){
             var mk=document.createElement('DIV');
             mk.style.position='absolute';
             mk.style.right=mk.style.bottom=mk.style.height=mk.style.width='0px';
             document.body.appendChild(mk);
             settings.mk=mk;
            }
     		if (settings.externalsource!='' && settings.display){ //if ajax content
    					alwaysOnTop.loadajaxcontent($, settings)
    			}
    			else if (settings.externalsource==''){ //inline content
    				var $target=$('#'+settings.targetid)
    				if (!settings.display){ //if hide content (based on frequency setting)
    					$target.hide()
    					return false
    				}
    				else{
     				alwaysOnTop.positiontarget($target, settings)
    				}
    			}
    		}) //end ready
    	},
    Code:
    	positiontarget:function($target, settings){
    		var fixedsupport=!document.all || document.all && document.compatMode=="CSS1Compat" && window.XMLHttpRequest //not IE or IE7+ browsers in standards mode
    		var posoptions={position:fixedsupport? 'fixed':'absolute', visibility:'visible'}
    		if (settings.fadeduration[0]>0) //if fade in
    			posoptions.opacity=0
        	posoptions[(/^[13]$/.test(settings.orientation))? 'left' : 'right']=settings.position[0]
    		posoptions[(/^[12]$/.test(settings.orientation))? 'top' : 'bottom']=settings.position[1]
    		if (document.all && !window.XMLHttpRequest) //loose check for IE6 and below
      			posoptions.width=$target.width() //IE6- seems to require an explicit width on a DIV
          if (settings.mk){
                posoptions['height']=$target.height();
                posoptions['left']=(settings.mk.offsetLeft-$target.width())/2+settings.position[0];
                posoptions['top']=(settings.mk.offsetTop-$target.height())/2+settings.position[1];
    		}
            $target.css(posoptions);
    		if (!fixedsupport){
    			this.keepfixed($target, settings)
    			var evtstr='scroll.' + settings.targetid + ' resize.'+settings.targetid
    			jQuery(window).bind(evtstr, function(){alwaysOnTop.keepfixed($target, settings)})
    		}
    		this.revealdiv($target, settings, fixedsupport)
    		if (settings.hideafter>0){ //if hide timer enabled
    			setTimeout(function(){
    				alwaysOnTop.hidediv(settings.targetid)
    			}, settings.hideafter+settings.fadeduration[0])
    		}
    	},
    Code:
    alwaysOnTop.init({
    	targetid: 'examplediv',
    	orientation: 5,  // 5 = center in window
    	position: [5, 10],
    	fadeduration: [1000, 1000],
    	frequency: 0.95,
    	hideafter: 15000
    })
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

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

    Zanato (04-08-2014)

  4. #3
    Join Date
    May 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Hi Vic and thank you very much for your reply.

    I tried copying in the parts only shown in red but it didn't work so I copied in all your code overwriting the old code and it worked perfect. So I guess you modified more than what you have shown in red.

    Thanks a million again!

  5. #4
    Join Date
    May 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Sorry guys...

    I tried to edit the thread title to show it as Resolved but it gave the warning - "Warning: Only variables should be passed by reference in ..../editpost.php on line 323" and it seems to have deleted my original post.

Similar Threads

  1. Stay on Top Content Script - Center?
    By fergusonkw in forum Dynamic Drive scripts help
    Replies: 7
    Last Post: 05-26-2013, 01:27 PM
  2. Resolved Stay on Top content script + delay + link
    By Luys in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 04-03-2011, 03:08 PM
  3. Stay On Top Content Script
    By Eddie in forum Dynamic Drive scripts help
    Replies: 6
    Last Post: 07-04-2009, 05:28 PM
  4. Stay On Top Content Script
    By kee1108 in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 06-25-2009, 07:53 PM
  5. question about Stay On Top Content script
    By evan5 in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 06-03-2009, 08:25 PM

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
  •