<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; JS: Помогитє поправить скрипт (кнопки вверх-вниз)]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=11185&amp;type=atom" />
	<updated>2015-12-29T12:42:16Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=11185</id>
		<entry>
			<title type="html"><![CDATA[Re: JS: Помогитє поправить скрипт (кнопки вверх-вниз)]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=100018#p100018" />
			<content type="html"><![CDATA[<p><strong>mozers</strong> ладно, спасибо и на этом.</p>]]></content>
			<author>
				<name><![CDATA[БлагоЯр]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=33571</uri>
			</author>
			<updated>2015-12-29T12:42:16Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=100018#p100018</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JS: Помогитє поправить скрипт (кнопки вверх-вниз)]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=100017#p100017" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>БлагоЯр пишет:</cite><blockquote><p>В каком месте находится точка активации (имею ввиду мышкой)?</p></blockquote></div><p>А фиг знает. Я и оригинальную смог активировать только по Ctl+Alt.</p><div class="quotebox"><cite>БлагоЯр пишет:</cite><blockquote><p>И по центру можно сделать?</p></blockquote></div><p>Чего &quot;по центру&quot;? И &quot;по центру&quot; чего?</p><div class="quotebox"><cite>БлагоЯр пишет:</cite><blockquote><p>кнопки возвращаются на середину и там остаются до перезагрузки страницы.</p></blockquote></div><p>Такого не наблюдаю, поэтому и поправить не смогу пока не словлю <img src="//forum.script-coding.com/img/smilies/sad.png" width="15" height="15" /><br />Увы, я не спец по user.script. Там есть свои тонкости. Я просто показал в каком месте можно поковыряться чтобы получить нужный эффект. Попробуй сам...</p>]]></content>
			<author>
				<name><![CDATA[mozers]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=4112</uri>
			</author>
			<updated>2015-12-29T12:33:48Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=100017#p100017</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JS: Помогитє поправить скрипт (кнопки вверх-вниз)]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=100014#p100014" />
			<content type="html"><![CDATA[<p><strong>mozers</strong><br />Почему-то не могу активировать, после того, как кнопки уезжают за край экрана. В каком месте находится точка активации (имею ввиду мышкой)?<br />И по центру можно сделать?</p><p>И какой-то глюк - когда сделал активацию по Ctrl+Alt, а потом к примеру просто Alt (для вызова панели меню), то кнопки возвращаются на середину и там остаются до перезагрузки страницы.</p><p>ПС. Для кого-то мясо - это хорошо, для кого-то нет. Это дело вкуса. Дело в том, что зачастую курсор пользователя находится ближе к центру, а не к краю экрана, поэтому для меня удобнее по центру.</p>]]></content>
			<author>
				<name><![CDATA[БлагоЯр]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=33571</uri>
			</author>
			<updated>2015-12-29T08:09:45Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=100014#p100014</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JS: Помогитє поправить скрипт (кнопки вверх-вниз)]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=100013#p100013" />
			<content type="html"><![CDATA[<p><strong>БлагоЯр</strong><br />Попробовал на Chrome+Tampermonkey. У меня кнопки находятся в центре правого края окна (по твоей терминологии middle-right) и, при простое, плавненько уплывают вправо за край окна. По моему - просто идеально. Так что я совершенно согласен с молчанием разработчика.<br />Но, тем не менее, &quot;если один человек сделал, то другой завсегда сломать сможет&quot; </p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><p>// ==UserScript==<br />// @name&nbsp; &nbsp; Lite Add button for Smooth Scroll to the top / bottom<br />// @author&nbsp; burningall<br />// @description 为页面添加按钮，平滑的滚动到顶部/底部<br />// @version&nbsp; &nbsp; &nbsp;2015.8.17<br />// @include&nbsp; &nbsp; &nbsp;*<br />// @grant&nbsp; &nbsp; &nbsp; &nbsp;GM_addStyle<br />// @run-at&nbsp; &nbsp; &nbsp; document-start<br />// @compatible&nbsp; chrome&nbsp; 完美支持<br />// @compatible&nbsp; firefox&nbsp; 完美支持<br />// @license&nbsp; &nbsp; &nbsp;The MIT License (MIT); http://opensource.org/licenses/MIT<br />// @supportURL&nbsp; &nbsp; &nbsp; http://www.burningall.com<br />// @contributionURL troy450409405@gmail.com|alipay.com<br />// @namespace https://greasyfork.org/zh-CN/users/3400-axetroy<br />// ==/UserScript==<br />// <br />// <br />// <br />//=======快捷键======<br />//alt+1&gt;&gt;&gt;&gt;&gt;&gt;回到顶部<br />//alt+2&gt;&gt;&gt;&gt;&gt;&gt;去到底部<br />//================公共函数区============<br />(function(window,document){</p><p>function addEvent(obj, type, fn){<br />&nbsp; &nbsp; return obj.addEventListener ?<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.addEventListener(type, function(e){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var ev = window.event ? window.event : (e ? e : null);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ev.target = ev.target || ev.srcElement;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if( fn.call(obj,ev)===false ){//回掉函数为false，则阻止默认时间<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.cancelBubble = true;//阻止冒泡<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.preventDefault();//chrome，firefox下阻止默认事件<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }, false)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.attachEvent(&#039;on&#039; + type, function(e){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //fn.call(obj,e);//解决IE8下，this是window的问题<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var ev = window.event ? window.event : (e ? e : null);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ev.target = ev.target || ev.srcElement;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(fn.call(obj,ev)===false ){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.cancelBubble = true;//阻止冒泡<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;//阻止默认事件，针对IE8<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br />}</p><p>function getSize(obj) {<br />&nbsp; &nbsp; return document.documentElement[obj] !== 0 ? document.documentElement[obj] : document.body[obj];<br />}</p><p>function hasScroll() {<br />&nbsp; &nbsp; return getSize(&#039;scrollHeight&#039;) &gt; getSize(&#039;clientHeight&#039;) ? true : false;<br />}</p><p>function getStyle(obj, attr) {<br />&nbsp; &nbsp; return obj.currentStyle ? obj.currentStyle[attr] : getComputedStyle(obj)[attr];<br />}</p><p>function $(id) {<br />&nbsp; &nbsp; return document.getElementById(id);<br />}<br />function animate(obj,json,cfgjson){<br />&nbsp; &nbsp; &nbsp; &nbsp; clearInterval(obj.animate);<br />&nbsp; &nbsp; &nbsp; &nbsp; obj.animate = setInterval(function() {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var bStop = true;//判断运动是否停止<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(var attr in json){//attr代表属性,&#039;width&#039;,&#039;height&#039;.而json[attr]代表数值<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 1. 取得当前的值（可以是width，height，opacity等的值）<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var objAttr = 0 ;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(attr == &#039;opacity&#039;){ //当前值<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; objAttr = Math.round(parseFloat( getStyle(obj,attr) ) * 100);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else if( attr==&quot;scrollTop&quot; ){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; objAttr = parseInt( getSize(&quot;scrollTop&quot;) );<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else{<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; objAttr = parseInt( getStyle(obj,attr) );<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 2.计算运动速度<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var jsonattr = parseFloat( json[attr] );//目标值<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var speedConfig = (cfgjson &amp;&amp; typeof ( cfgjson.speed ) != &#039;undefined&#039;) ? cfgjson.speed : 10;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var iSpeed = (jsonattr - objAttr) / speedConfig;&nbsp; &nbsp; //(目标数值-当前数值)/10<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; iSpeed = iSpeed &gt; 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);&nbsp; &nbsp;//如果速度&gt;0，则速度向上取整，如果小于0，则保留小数<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 3. 检测所有运动是否到达目标<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //objAttr,当前点，json[attr]为目标点<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( (iSpeed&gt;0 &amp;&amp; objAttr &lt;= jsonattr) || (iSpeed&lt;0 &amp;&amp; objAttr &gt;= jsonattr) ) {//如果有其中一项没有达到目标<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bStop = false;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (attr == &quot;opacity&quot;) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.style.filter = &#039;alpha(opacity:&#039; + (objAttr + iSpeed) + &#039;)&#039;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.style.opacity = (objAttr + iSpeed) / 100;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else if(attr == &quot;scrollTop&quot;){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.documentElement.scrollTop=document.body.scrollTop = objAttr+iSpeed;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.style[attr] = objAttr + iSpeed + &#039;px&#039;;&nbsp; //赋值开始运动<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (bStop) { // 表示所有运动都到达目标值<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clearInterval(obj.animate);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if( cfgjson &amp;&amp; typeof cfgjson.endFn != &#039;undefined&#039; ){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cfgjson.endFn.call(obj);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }//for<br />&nbsp; &nbsp; &nbsp; &nbsp; },20);<br />}<br />//================样式区============<br />var cssText = &#039;#scrollMars-troy{position:fixed;right:30px;bottom:30px;z-index:9999999}#scrollMars-troy #mars-point{width:100px;height:100px;position:absolute;top:0;left:-40px}#scrollMars-troy div div.sroll-btn-troy{width:50px;height:50px;text-align:center;background:#303030;color:#fff;display:block;opacity:0.8;filter:alpha(opacity=80);cursor:pointer;border-radius:50%;box-shadow:2px 2px 40px 2px #303030;line-height:50px;font-size:35px;font-style:inherit;font-weight:bold;font-family:&quot;宋体&quot;}#scrollMars-troy div div.sroll-btn-troy:hover{background:#FF0000}&#039;;<br />GM_addStyle(cssText);<br />//================主要代码区============<br />function scroll(dir) { //obj随意，dir&gt;0往上滚，dir&lt;0往下滚<br />&nbsp; &nbsp; var position,speed,scrollTop,scrollHeight,clientHeight;<br />&nbsp; &nbsp; clearInterval(document.timerScroll);<br />&nbsp; &nbsp; scrollHeight = getSize(&#039;scrollHeight&#039;);<br />&nbsp; &nbsp; clientHeight = getSize(&#039;clientHeight&#039;);<br />&nbsp; &nbsp; document.timerScroll = setInterval(function() {<br />&nbsp; &nbsp; &nbsp; &nbsp; scrollTop = getSize(&#039;scrollTop&#039;);&nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; if (dir &gt; 0) { //往上滚动<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; speed = ( scrollTop/10 ) + 1;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; position = scrollTop - speed;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (position &lt;= 0) { //如果滚到顶部<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.body.scrollTop = document.documentElement.scrollTop = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clearInterval(document.timerScroll);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; } else { //往下滚动<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; speed = ( (scrollHeight-scrollTop-clientHeight) / 10 ) + 1;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; position = scrollTop + speed;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (position + clientHeight &gt;= scrollHeight) { //如果滚到底部<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.body.scrollTop = document.documentElement.scrollTop = scrollHeight;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clearInterval(document.timerScroll);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; document.body.scrollTop = document.documentElement.scrollTop = position;<br />&nbsp; &nbsp; }, 20);<br />}</p><p>function marsMove(dir){<br />&nbsp; &nbsp; var mars = $(&#039;scrollMars-troy&#039;);<br />&nbsp; &nbsp; var point = $(&#039;mars-point&#039;);<br />&nbsp; &nbsp; if(dir==&quot;moveIn&quot;){//移入<br />&nbsp; &nbsp; &nbsp; &nbsp; clearTimeout(mars.timerHover); <br />&nbsp; &nbsp; &nbsp; &nbsp; animate(mars,{&quot;bottom&quot;:&quot;30&quot;,&quot;opacity&quot;:&quot;100&quot;});<br />&nbsp; &nbsp; &nbsp; &nbsp; animate(point,{&quot;left&quot;:&quot;0&quot;});<br />&nbsp; &nbsp; }else if(dir==&quot;moveOut&quot;){//移出<br />&nbsp; &nbsp; &nbsp; &nbsp; clearTimeout(mars.timerHover);<br />&nbsp; &nbsp; &nbsp; &nbsp; mars.timerHover = setTimeout(function(){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; animate(mars,{&quot;bottom&quot;:&quot;-130&quot;,&quot;opacity&quot;:&quot;30&quot;});<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; animate(point,{&quot;left&quot;:&quot;-40&quot;});<br />&nbsp; &nbsp; &nbsp; &nbsp; },3000);<br />&nbsp; &nbsp; }<br />}</p><p>function init() {<br />&nbsp; &nbsp; var scrollBtn = $(&quot;scrollMars-troy&quot;);<br />&nbsp; &nbsp; if( scrollBtn ){<br />&nbsp; &nbsp; &nbsp; &nbsp; scrollBtn.style.top = (getSize(&#039;clientHeight&#039;) / 3) + &#039;px&#039;;<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; if (hasScroll() === true &amp;&amp; !scrollBtn) { //如果有滚动条，并且没有按钮<br />&nbsp; &nbsp; &nbsp; &nbsp; var mars = document.createElement(&#039;div&#039;),goTop,goBtm,point;<br />&nbsp; &nbsp; &nbsp; &nbsp; mars.id = &quot;scrollMars-troy&quot;;<br />&nbsp; &nbsp; &nbsp; &nbsp; window.top.document.documentElement.appendChild(mars);<br />&nbsp; &nbsp; &nbsp; &nbsp; mars.innerHTML = <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;&lt;div id=\&#039;mars-point\&#039;&gt;&lt;/div&gt;&#039;+<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;&lt;div&gt;&#039;+<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;&nbsp; &nbsp; &lt;div id=\&#039;goTop-troy\&#039; title=\&#039;Up\&#039; class=\&#039;sroll-btn-troy\&#039;&gt;&lt;/div&gt;&#039;+<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;&nbsp; &nbsp; &lt;div id=\&#039;goBtm-troy\&#039; title=\&#039;Down\&#039; class=\&#039;sroll-btn-troy\&#039;&gt;&lt;/div&gt;&#039;+<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;&lt;/div&gt;&#039;;<br />&nbsp; &nbsp; &nbsp; &nbsp; goTop = $(&quot;goTop-troy&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; goBtm = $(&quot;goBtm-troy&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; goTop.innerHTML = &quot;↑&quot;;<br />&nbsp; &nbsp; &nbsp; &nbsp; goBtm.innerHTML = &quot;↓&quot;;<br />&nbsp; &nbsp; &nbsp; &nbsp; // $(&#039;scrollMars-troy&#039;).style.top = (getSize(&#039;clientHeight&#039;) / 3) + &#039;px&#039;;<br />&nbsp; &nbsp; &nbsp; &nbsp; addEvent(goTop, &quot;click&quot;, function() {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scroll(1);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;<br />&nbsp; &nbsp; &nbsp; &nbsp; });<br />&nbsp; &nbsp; &nbsp; &nbsp; addEvent(goBtm, &quot;click&quot;, function() {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scroll(-1);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;<br />&nbsp; &nbsp; &nbsp; &nbsp; });<br />&nbsp; &nbsp; &nbsp; &nbsp; addEvent(mars,&#039;mouseover&#039;,function(){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; marsMove(&quot;moveIn&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;<br />&nbsp; &nbsp; &nbsp; &nbsp; });<br />&nbsp; &nbsp; &nbsp; &nbsp; addEvent(mars,&#039;mouseout&#039;,function(){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; marsMove(&quot;moveOut&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;<br />&nbsp; &nbsp; &nbsp; &nbsp; });<br />&nbsp; &nbsp; &nbsp; &nbsp; addEvent(mars,&#039;mousedown&#039;,function(){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;<br />&nbsp; &nbsp; &nbsp; &nbsp; });<br />&nbsp; &nbsp; &nbsp; &nbsp; marsMove(&quot;moveOut&quot;);<br />&nbsp; &nbsp; }<br />}<br />//================执行区============<br />addEvent(window,&quot;mousewheel&quot;,function(){<br />&nbsp; &nbsp; clearInterval(document.timerScroll);<br />});<br />addEvent(window,&quot;DOMMouseScroll&quot;,function(){<br />&nbsp; &nbsp; clearInterval(document.timerScroll);<br />});<br />addEvent(window.top, &quot;resize&quot;, function() { //页面大小改变，初始化按钮<br />&nbsp; &nbsp; init();<br />});</p><p>addEvent(document, &#039;DOMContentLoaded&#039;, function() {<br />&nbsp; &nbsp; init();<br />});<br />//================快捷键区============<br />addEvent(window, &#039;keydown&#039;, function(e) {<br />&nbsp; &nbsp; if (e.altKey &amp;&amp; e.keyCode == 49) { //alt+1，向上滚动<br />&nbsp; &nbsp; &nbsp; &nbsp; scroll(1);<br />&nbsp; &nbsp; } else if (e.altKey &amp;&amp; e.keyCode == 50) { //alt+2，向下滚动<br />&nbsp; &nbsp; &nbsp; &nbsp; scroll(-1);<br />&nbsp; &nbsp; } else if (e.ctrlKey &amp;&amp; e.altKey) { //ctrl+alt,调出按钮<br />&nbsp; &nbsp; &nbsp; &nbsp; marsMove(&quot;moveIn&quot;);<br />&nbsp; &nbsp; } <br />});//监听keydown，快捷键</p><p>})(window,document);</p></div></div><p>В таком варианте кнопки находятся справа-внизу и, при бездействии, уплывают за нижний край окна, откуда их можно вызвать, как и в оригинале, комбинацией Crtl+Alt.</p>]]></content>
			<author>
				<name><![CDATA[mozers]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=4112</uri>
			</author>
			<updated>2015-12-29T07:41:52Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=100013#p100013</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[JS: Помогитє поправить скрипт (кнопки вверх-вниз)]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=100001#p100001" />
			<content type="html"><![CDATA[<p>Сейчас у кнопок позиция такая - bottom-right.<br />И если не используются, то уезжают вправо. Хочется, чтобы они имели позицию - bottom и также уезжали вниз.</p><br /><p>ПС. Разработчика просил, не отвечает уже давно.<br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><div class="codebox"><pre><code>
// ==UserScript==
// @name    Lite Add button for Smooth Scroll to the top / bottom
// @author  burningall
// @description 为页面添加按钮，平滑的滚动到顶部/底部
// @version     2015.8.17
// @include     *
// @grant       GM_addStyle
// @run-at      document-start
// @compatible  chrome  完美支持
// @compatible  firefox  完美支持
// @license     The MIT License (MIT); http://opensource.org/licenses/MIT
// @supportURL      http://www.burningall.com
// @contributionURL troy450409405@gmail.com|alipay.com
// @namespace https://greasyfork.org/zh-CN/users/3400-axetroy
// ==/UserScript==
// 
// 
// 
//=======快捷键======
//alt+1&gt;&gt;&gt;&gt;&gt;&gt;回到顶部
//alt+2&gt;&gt;&gt;&gt;&gt;&gt;去到底部
//================公共函数区============
(function(window,document){

function addEvent(obj, type, fn){
    return obj.addEventListener ?
            obj.addEventListener(type, function(e){
                var ev = window.event ? window.event : (e ? e : null);
                ev.target = ev.target || ev.srcElement;
                if( fn.call(obj,ev)===false ){//回掉函数为false，则阻止默认时间
                    e.cancelBubble = true;//阻止冒泡
                    e.preventDefault();//chrome，firefox下阻止默认事件
                }
            }, false)
             :
            obj.attachEvent(&#039;on&#039; + type, function(e){
                //fn.call(obj,e);//解决IE8下，this是window的问题
                var ev = window.event ? window.event : (e ? e : null);
                ev.target = ev.target || ev.srcElement;
                if(fn.call(obj,ev)===false ){
                    e.cancelBubble = true;//阻止冒泡
                    return false;//阻止默认事件，针对IE8
                }
            });
}

function getSize(obj) {
    return document.documentElement[obj] !== 0 ? document.documentElement[obj] : document.body[obj];
}

function hasScroll() {
    return getSize(&#039;scrollHeight&#039;) &gt; getSize(&#039;clientHeight&#039;) ? true : false;
}

function getStyle(obj, attr) {
    return obj.currentStyle ? obj.currentStyle[attr] : getComputedStyle(obj)[attr];
}

function $(id) {
    return document.getElementById(id);
}
function animate(obj,json,cfgjson){
        clearInterval(obj.animate);
        obj.animate = setInterval(function() {
            var bStop = true;//判断运动是否停止
            for(var attr in json){//attr代表属性,&#039;width&#039;,&#039;height&#039;.而json[attr]代表数值
                // 1. 取得当前的值（可以是width，height，opacity等的值）
                var objAttr = 0 ;
                if(attr == &#039;opacity&#039;){ //当前值
                    objAttr = Math.round(parseFloat( getStyle(obj,attr) ) * 100);
                }else if( attr==&quot;scrollTop&quot; ){
                    objAttr = parseInt( getSize(&quot;scrollTop&quot;) );
                }
                else{
                    objAttr = parseInt( getStyle(obj,attr) );
                }
                // 2.计算运动速度
                var jsonattr = parseFloat( json[attr] );//目标值
                var speedConfig = (cfgjson &amp;&amp; typeof ( cfgjson.speed ) != &#039;undefined&#039;) ? cfgjson.speed : 10;
                var iSpeed = (jsonattr - objAttr) / speedConfig;    //(目标数值-当前数值)/10
                iSpeed = iSpeed &gt; 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);   //如果速度&gt;0，则速度向上取整，如果小于0，则保留小数
                // 3. 检测所有运动是否到达目标
                //objAttr,当前点，json[attr]为目标点
                if ( (iSpeed&gt;0 &amp;&amp; objAttr &lt;= jsonattr) || (iSpeed&lt;0 &amp;&amp; objAttr &gt;= jsonattr) ) {//如果有其中一项没有达到目标
                    bStop = false;
                }
                if (attr == &quot;opacity&quot;) {
                    obj.style.filter = &#039;alpha(opacity:&#039; + (objAttr + iSpeed) + &#039;)&#039;;
                    obj.style.opacity = (objAttr + iSpeed) / 100;
                }else if(attr == &quot;scrollTop&quot;){
                    document.documentElement.scrollTop=document.body.scrollTop = objAttr+iSpeed;
                }
                else {
                    obj.style[attr] = objAttr + iSpeed + &#039;px&#039;;  //赋值开始运动
                }
                if (bStop) { // 表示所有运动都到达目标值
                    clearInterval(obj.animate);
                    if( cfgjson &amp;&amp; typeof cfgjson.endFn != &#039;undefined&#039; ){
                        cfgjson.endFn.call(obj);
                    }
                }
            }//for
        },20);
}
//================样式区============
    var cssText = &#039;#scrollMars-troy{position:fixed;right:30px;z-index:9999999}#scrollMars-troy #mars-point{width:100px;height:100px;position:absolute;top:0;left:-40px}#scrollMars-troy div div.sroll-btn-troy{width:35px;height:35px;text-align:center;background:transparent;color:#000;text-shadow:0 0 3px #000;display:block;opacity:0.8;filter:alpha(opacity=80);cursor:pointer;border-radius:15%;line-height:35px;font-size:25px;font-style:inherit;font-weight:bold;font-family:&quot;宋体&quot;}#scrollMars-troy div div.sroll-btn-troy:hover{background:#9acd32}&#039;;
GM_addStyle(cssText);
//================主要代码区============
function scroll(dir) { //obj随意，dir&gt;0往上滚，dir&lt;0往下滚
    var position,speed,scrollTop,scrollHeight,clientHeight;
    clearInterval(document.timerScroll);
    scrollHeight = getSize(&#039;scrollHeight&#039;);
    clientHeight = getSize(&#039;clientHeight&#039;);
    document.timerScroll = setInterval(function() {
        scrollTop = getSize(&#039;scrollTop&#039;);   
        if (dir &gt; 0) { //往上滚动
            speed = ( scrollTop/10 ) + 1;
            position = scrollTop - speed;
            if (position &lt;= 0) { //如果滚到顶部
                document.body.scrollTop = document.documentElement.scrollTop = 0;
                clearInterval(document.timerScroll);
            }
        } else { //往下滚动
            speed = ( (scrollHeight-scrollTop-clientHeight) / 10 ) + 1;
            position = scrollTop + speed;
            if (position + clientHeight &gt;= scrollHeight) { //如果滚到底部
                document.body.scrollTop = document.documentElement.scrollTop = scrollHeight;
                clearInterval(document.timerScroll);
            }
        }
        document.body.scrollTop = document.documentElement.scrollTop = position;
    }, 20);
}

function marsMove(dir){
    var mars = $(&#039;scrollMars-troy&#039;);
    var point = $(&#039;mars-point&#039;);
    if(dir==&quot;moveIn&quot;){//移入
        clearTimeout(mars.timerHover); 
        animate(mars,{&quot;right&quot;:&quot;10&quot;,&quot;opacity&quot;:&quot;100&quot;});
        animate(point,{&quot;left&quot;:&quot;0&quot;});
    }else if(dir==&quot;moveOut&quot;){//移出
        clearTimeout(mars.timerHover);
        mars.timerHover = setTimeout(function(){
            animate(mars,{&quot;right&quot;:&quot;-10&quot;,&quot;opacity&quot;:&quot;20&quot;});
            animate(point,{&quot;left&quot;:&quot;-20&quot;});
        },3000);
    }
}

function init() {
    var scrollBtn = $(&quot;scrollMars-troy&quot;);
    if( scrollBtn ){
        scrollBtn.style.top = (getSize(&#039;clientHeight&#039;) / 3) + &#039;px&#039;;
    }
    if (hasScroll() === true &amp;&amp; !scrollBtn) { //如果有滚动条，并且没有按钮
        var mars = document.createElement(&#039;div&#039;),goTop,goBtm,point;
        mars.id = &quot;scrollMars-troy&quot;;
        window.top.document.documentElement.appendChild(mars);
        mars.innerHTML = 
            &#039;&lt;div id=\&#039;mars-point\&#039;&gt;&lt;/div&gt;&#039;+
            &#039;&lt;div&gt;&#039;+
            &#039;    &lt;div id=\&#039;goTop-troy\&#039; title=\&#039;返回顶部\&#039; class=\&#039;sroll-btn-troy\&#039;&gt;&lt;/div&gt;&#039;+
            &#039;    &lt;div id=\&#039;goBtm-troy\&#039; title=\&#039;去到底部\&#039; class=\&#039;sroll-btn-troy\&#039;&gt;&lt;/div&gt;&#039;+
            &#039;&lt;/div&gt;&#039;;
        goTop = $(&quot;goTop-troy&quot;);
        goBtm = $(&quot;goBtm-troy&quot;);
        goTop.innerHTML = &quot;↑&quot;;
        goBtm.innerHTML = &quot;↓&quot;;
        $(&#039;scrollMars-troy&#039;).style.top = (getSize(&#039;clientHeight&#039;) / 1.15) + &#039;px&#039;;
        addEvent(goTop, &quot;click&quot;, function() {
            scroll(1);
            return false;
        });
        addEvent(goBtm, &quot;click&quot;, function() {
            scroll(-1);
            return false;
        });
        addEvent(mars,&#039;mouseover&#039;,function(){
            marsMove(&quot;moveIn&quot;);
            return false;
        });
        addEvent(mars,&#039;mouseout&#039;,function(){
            marsMove(&quot;moveOut&quot;);
            return false;
        });
        addEvent(mars,&#039;mousedown&#039;,function(){
            return false;
        });
        marsMove(&quot;moveOut&quot;);
    }
}
//================执行区============
addEvent(window,&quot;mousewheel&quot;,function(){
    clearInterval(document.timerScroll);
});
addEvent(window,&quot;DOMMouseScroll&quot;,function(){
    clearInterval(document.timerScroll);
});
addEvent(window.top, &quot;resize&quot;, function() { //页面大小改变，初始化按钮
    init();
});

addEvent(document, &#039;DOMContentLoaded&#039;, function() {
    init();
});
//================快捷键区============
addEvent(window, &#039;keydown&#039;, function(e) {
    if (e.altKey &amp;&amp; e.keyCode == 49) { //alt+1，向上滚动
        scroll(1);
    } else if (e.altKey &amp;&amp; e.keyCode == 50) { //alt+2，向下滚动
        scroll(-1);
    } else if (e.ctrlKey &amp;&amp; e.altKey) { //ctrl+alt,调出按钮
        marsMove(&quot;moveIn&quot;);
    } 
});//监听keydown，快捷键

})(window,document);
</code></pre></div></div></div>]]></content>
			<author>
				<name><![CDATA[БлагоЯр]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=33571</uri>
			</author>
			<updated>2015-12-28T12:10:24Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=100001#p100001</id>
		</entry>
</feed>
