Scrolltop css
Author: V | 2025-04-23
เป็นการใช้ jQuery Css กับ .scrollTop() ในการกำหนดความสูงของ Scollbar ว่ามีความสูงเท่าไหร่ถึงจะขึ้น Scollbar โดยอ้างถึงตำแหน่งในด้านซ้าย scrollTop Syntax .scrollTop() .scrollTop( value )
jquery - animate - scrollTop in Css - Stack Overflow
The Element.scrollTop property gets or sets the number of pixels that an element's content is scrolled vertically. An element's scrollTop value is a measurement of the distance from the element's top to its topmost visible content. When an element's content does not generate a vertical scrollbar, then its scrollTop value is 0. scrollTop can be set to any integer value, with certain caveats: If the element can't be scrolled (e.g. it has no overflow or if the element has a property of "non-scrollable"), scrollTop is 0. scrollTop doesn't respond to negative values; instead, it sets itself back to 0. If set to a value greater than the maximum available for the element, scrollTop settles itself to the maximum value. When scrollTop is used on the root element (the element), the scrollY of the window is returned. This is a special case of scrollTop. Warning: On systems using display scaling, scrollTop may give you a decimal value.A number.In this example, try scrolling the inner container with the dashed border, and see how the value of scrollTop changes. HTML div id="container"> div id="scroller"> p> Far out in the uncharted backwaters of the unfashionable end of the western spiral arm of the Galaxy lies a small unregarded yellow sun. Orbiting this at a distance of roughly ninety-two million miles is an utterly insignificant little blue green planet whose ape-descended life forms are so amazingly primitive that they still think digital watches are a pretty neat idea. p> div>div>div id="output">scrollTop: 0div> CSS #scroller { overflow: scroll; height: 150px; width: 150px; border: 5px dashed orange;}#output { padding: 1rem 0;} JavaScript const scroller = document.querySelector("#scroller");const output = document.querySelector("#output");scroller.addEventListener("scroll", (event) => { output.textContent = `scrollTop: ${scroller.scrollTop}`;}); Result Classification result to JSON file to build an external API.You may find the Flask official documentation helpful.from flask import Flask, render_template, request, jsonifyimport nltkimport picklefrom nltk.corpus import stopwordsimport refrom nltk.stem.porter import PorterStemmerapp = Flask(__name__)ps = PorterStemmer()# Load model and vectorizermodel = pickle.load(open('model2.pkl', 'rb'))tfidfvect = pickle.load(open('tfidfvect2.pkl', 'rb'))# Build functionalities@app.route('/', methods=['GET'])def home(): return render_template('index.html')def predict(text): review = re.sub('[^a-zA-Z]', ' ', text) review = review.lower() review = review.split() review = [ps.stem(word) for word in review if not word in stopwords.words('english')] review = ' '.join(review) review_vect = tfidfvect.transform([review]).toarray() prediction = 'FAKE' if model.predict(review_vect) == 0 else 'REAL' return prediction@app.route('/', methods=['POST'])def webapp(): text = request.form['text'] prediction = predict(text) return render_template('index.html', text=text, result=prediction)@app.route('/predict/', methods=['GET','POST'])def api(): text = request.args.get("text") prediction = predict(text) return jsonify(prediction=prediction)if __name__ == "__main__": app.run()You can see an index.html file in the previous section, and it’s the home page of the application. Create a folder named "Templates" in the root folder, and create a file "index.html" inside. Now let’s add some content to the page. Fake News Prediction [email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> [email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"> FAKE NEWS PREDICTION API Blog NoteBook Code Source A fake news prediction web application using Machine Learning algorithms, deployed using Django and Heroku. Enter your text to try it. {{text}} Predict {% if result %} Prediction : {{result}} {% endif %} function growTextarea (i,elem) { var elem = $(elem); var resizeTextarea = function( elem ) { var scrollLeft = window.pageXOffset || (document.documentElement || document.body.parentNode || document.body).scrollLeft; var scrollTop = window.pageYOffset || (document.documentElement || document.body.parentNode || document.body).scrollTop; elem.css('height', 'auto').css('height', elem.prop('scrollHeight') ); window.scrollTo(scrollLeft, scrollTop); }; elem.on('input', function() { resizeTextarea( $(this) ); }); resizeTextarea( $(elem) ); } $('.jTextarea').each(growTextarea);The above script creates a web page like this:The fake news detection web app UI (Image by the author)Now you can run your app by typing the following command in your terminal:python3 app.pyYou will be able to run your app locally and have a test on the model.ConclusionIn this tutorial, you built a machine learning model to detect fake news from real ones from scratch and saved the model to build a web application using Flask. The web application is running in your local machine, and you can try to make it public using cloud services such as Heroku, AWS or DigitalOcean. I have deployed mine on Heroku. Feel free to have a try.I hope you enjoy this journey. Welcome to leave a comment and connect with me on Linkedin.css - Jquery Popup scrolltop - Stack Overflow
Material ScrollTop ButtonUpgrade instructions 1.x → 2.xLightweight, Material Design inspired button for scroll-to-top of the page (jQuery plugin).Just hit the button to smoothly scroll back to the top of the page. Here's the demo.LightweightMaterial Design inspiredWith ripple effectSmoothly animatedCustomizableWith some useful options...jQuery + CSS, (TypeScript + SCSS)Demo (example)Watch this: yarn or npmyarn add material-scrolltopManual install (download)If you want the latest stable version, get the latest release from the releases page and use dist folder.UsageInclude the files as shown in the code snippets below and you're done.NOTE: The only dependency for this plugin to work is jQuery library (don't forget!)In your add:">link rel="stylesheet" href="dist/material-scrolltop.css" />script src="dist/material-scrolltop.js">script>Then, before your closing tag add: $('body').materialScrollTop();">button class="material-scrolltop" type="button">button>script> $('body').materialScrollTop();script>SettingsOptionTypeDefaultDescriptionrevealElementstringbodyReveal button when scrolling over specific elementrevealPositionstringtopElement position for reveal button ('top' or 'bottom')paddingnumber0Adjusts little ups and downs in scrolling (can be negative number)durationnumber600Determining how long the animation will runeasingstring'swing'Indicating which easing function to use for the transition animate()onScrollEndFunction()falseA function to call once the animation is completeExample (advanced usage) element ... padding: 100, // ... and add padding 100px revealElement: 'header', // Reveal button when scrolling over ... revealPosition: 'bottom', // ... and do it at the end of element duration: 600, // Animation will run 600 ms easing: 'swing', // Do it with swing animation onScrollEnd: function () { // Give me some log when animation ends console.log('This is the end, my only friend, the end...'); },});">$('body').materialScrollTop({ // Scroll to the top of element ... padding: 100, // ... and add padding 100px revealElement: 'header', // Reveal button when scrolling over ... revealPosition: 'bottom', // ... and do it at the end of element duration: 600, // Animation will run 600 ms easing: 'swing', // Do it with swing animation onScrollEnd: function () { // Give me some log when animation ends console.log('This is the end, my only friend, the end...'); },});Foldersmaterial-scrolltop/├── src/| ├── icons/│ | └── top-arrow.svg│ ├── material-scrolltop.scss│ └── material-scrolltop.ts├── dist/| ├── icons/│ | └── top-arrow.svg│ ├── material-scrolltop.css│ └── material-scrolltop.js└── demo/ ├── ... └── index.html └── examples/src/ (for development)TypeScript + SCSS source files.ts, .scsswhich are NOT executable in browserdist/ (for production)JavaScript + CSSexecutable in browser and compiled from src/ folder with command yarn builddemo/ (example page)In this folder you can see an example in real use.CustomizationColors, sizes and stuffUsing SASS (this file in 'src' folder), you can simply edit default styles, colors, position and customize plugin to fit your needs. 👍 (Or just edit directly css stylesheet)Hint: Modify scss file, run yarn build and see the demo.IconsSVGYou can change svg icon in icons/ directory.Custom text or signTurn off svg icon as sass variable: $mst-icon: falseBuild your new stylesheet yarn build (now without svg icon)Put your new sign or text inside html element like this:. เป็นการใช้ jQuery Css กับ .scrollTop() ในการกำหนดความสูงของ Scollbar ว่ามีความสูงเท่าไหร่ถึงจะขึ้น Scollbar โดยอ้างถึงตำแหน่งในด้านซ้าย scrollTop Syntax .scrollTop() .scrollTop( value ) The scrollTop() method is an inbuilt method in jQuery which is used to return the top vertical position of the scrollbar. Syntax: $(selector).scrollTop(position) The css() methodcss - jQuery: Adding additional pixels to the scrollTop - Stack
(mg) 4 Protein (g) 0 Sugar (g) 0 Serving Size 20 Oz Calories Per Serving 110 Fat (g) 0 Trans Fat (g) 0 Saturated Fat (g) 0 Carbs (g) 28 Fiber (g) 0 Sodium (mg) 0 Protein (g) 0 Sugar (g) 28 Side Sauces Serving Size 2 Oz Calories Per Serving 80 Fat (g) 0 Trans Fat (g) 0 Saturated Fat (g) 0 Carbs (g) 20 Fiber (g) 0 Sodium (mg) 20 Protein (g) 0 Sugar (g) 18 Serving Size 2 Oz Calories Per Serving 40 Fat (g) 0 Trans Fat (g) 0 Saturated Fat (g) 0 Carbs (g) 9 Fiber (g) 0 Sodium (mg) 910 Protein (g) 1 Sugar (g) 8 Serving Size 2 Oz Calories Per Serving 100 Fat (g) 0 Trans Fat (g) 0 Saturated Fat (g) 0 Carbs (g) 4 Fiber (g) 0 Sodium (mg) 90 Protein (g) 5 Sugar (g) 1 Serving Size 8 G Calories Per Serving 0 Fat (g) 0 Trans Fat (g) 0 Saturated Fat (g) 0 Carbs (g) 0 Fiber (g) 0 Sodium (mg) 150 Protein (g) 0 Sugar (g) 0 jQuery(document).ready(function($) { if($(window).width() >= 768){ var $details = $(".category-sidebar"), detailsPos = $details.position().top; $(window).on("scroll", function() { if ($(window).scrollTop() > 260) $details.css("position", "fixed").css("top","auto").css("bottom", 20).css("z-index", -1); else $details.css("position", "relative").css("top", 0); }) } }); --> There isn’t any speed option defined in the specification for manipulating the animation speed.Here's the associated demo:Solution ReviewIt's a great and promising CSS feature, and its browser support gradually grows. That said, even Safari, which lacked support in its previous versions, has started supporting it. We'll continue with the traditional jQuery approach. That said, to create smooth scrolling with jQuery, we’ll take advantage of its animate() method. Each time we click on a navigation link, we’ll do the following things:Cancel its default behavior to jump to the corresponding section.Grab its href attribute value. Smoothly navigate to the associated section by animating the scrollTop property. Note that the animate() method allows us to adjust the animation speed. In our case, the animation will last 800ms.Here’s the jQuery code:1$(".page-header ul a").on("click", function (e) {2 // 13 e.preventDefault();4 // 25 const href = $(this).attr("href");6 // 37 $("html, body").animate({ scrollTop: $(href).offset().top }, 800);8});And the related demo:Solution ReviewThe major downside of this method is that you have to load an extra JavaScript library. On the contrary, it's a reliable solution that will work well on different screens/devices, and you can customize the scrolling speed. Go with it only if your project already uses or needs jQuery.At this point, we’ll throw away jQuery and concentrate on two pure JavaScript solutions. Happily enough, it’s much simpler than you might expect. Using the scroll() MethodFirst, we’ll use the scroll() method. The logic for this approach is similar to the previous jQuery implementation. Inside this method, we’ll determine the scrolling behavior via the behavior configuration property. This property is the JavaScript representation of the scroll-behavior CSS property and can receive the auto (default), smooth and instant (see upcoming section 7) values. Again here, all we have to do is set the value of the behavior property to smooth.Here’s the required code:1const links = document.querySelectorAll(".page-header ul a");23for (const link of links) {4 link.addEventListener("click", clickHandler);5}67function clickHandler(e) {8 e.preventDefault();9 const href = this.getAttribute("href");10 const offsetTop = document.querySelector(href).offsetTop;1112 scroll({13 top: offsetTop,14 behavior: "smooth"15 });16}Instead of the scroll() method, we could equally have used the scrollTo() and scrollBy() methods. The effect should look theCSS Zoom interfering with jQuery scrollTop - Stack Overflow
Hi RichardSa,Refer below example.HTML Cosmic .wrapper { background-repeat: no-repeat; height: 1000px; background-position: center; background-size: cover; overflow: hidden; position: relative; } .footer { width: 100%; position: fixed !important; } .top { height: 100%; background-size: cover; background-color: rgb(245, 245, 245); width: 100%; z-index: 100; } .navbar-nav { margin-left: auto; } #navbarNav li a { color: #eeeeee; font-family: 'Be Vietnam', sans-serif; font-size: 11pt; font-weight: bolder; } .nav-item { float: right; } .navbar-nav .active { color: #eeeeee; } #navbarNav li a::after:hover { color: #eeeeee; } .navbar-brand:hover { color: #eeeeee; } .container2 { width: 100%; } .container { width: 100%; } .title { line-height: 1.33; letter-spacing: -.5px; margin-bottom: 5px; margin-top: 0%; } .desc { margin-bottom: 50px; margin-top: 12px; line-height: 1.7; } @media(min-width:992px) { .col-md-6:not(:first-child) { } .col-md-6:not(:last-child) { border-right: 1px solid #200662; border-left: 1px; } .form-horizontal { line-height: 1.33; letter-spacing: -.5px; margin-bottom: 5px; margin-top: 0%; } } #btnstart { border-radius: 5px; background-color: #32657c; font-weight: 500; font-size: 12pt; } #btnstart:hover { color: #eeeeee; background-color: steelblue; } #working { border-radius: 5px; background-color: #32657c; font-weight: 500; font-size: 11pt; } .img-circle { border-radius: 50%; float: left; } #imgone { width: 100%; height: auto; } @media screen and (min-width: 360px) and (max-width:640px) { #imgone { width: 100%; height: auto; } #boldhead { font-size: 17pt; } } .frontimg { width: 100%; height: auto; } .image-fluid { } .column { float: left; width: 33.33%; padding: 5px; } .row::after { content: ""; clear: both; display: table; } @media screen and (max-width: 500px) { .column { width: 100%; } } #newclients { font-family: 'Be Vietnam', sans-serif; } span.step { background: #ececed; border-radius: 1.6em; -moz-border-radius: 1.6em; -webkit-border-radius: 1.6em; color: #ffffff; display: inline-block; font-weight: bold; line-height: 2.5em; text-align: center; width: 2.5em; margin-left: auto; margin-right: auto; font-size: 20pt; } #dots { width: 100%; height: auto; position: absolute; background-size: cover; background-repeat: no-repeat; opacity: 0.2; margin-top: -29%; } #img6 { width: 100%; height: 200px; } #img7 { width: 100%; height: 200px; } #img0 { width: 100%; height: 200px; } @media screen and (min-width: 360px) and (max-width:640px) { #qr { display: none; } } .navbar-toggler > .close { display: inline; } .navbar-toggler.collapsed > .close, .navbar-toggler:not(.collapsed) > .navbar-toggler-icon { display: none; } $(window).scroll(function () { if ($(window).scrollTop() >= 50) { $('.navbar').css('background', '#32657c'); $('.nav-link').css('color', '#eeeeee'); $('.navbar-brand').css('color', '#eeeeee'); $('#newclients').css('color', '#eeeeee'); $('#newclients').css('border-color', '#eeeeee'); $('#newclients').css('background', '#32657c'); } else { $('.navbar').css('background', 'transparent'); $('.nav-link').css('color', '#32657c'); $('.navbar-brand').css('color', '#32657c'); $('#newclients').css('border-color', '#32657c'); $('#newclients').css('color', '#32657c'); $('#newclients').css('background', 'transparent'); } if (!$('#dvMobile').is(':hidden')) { $('.navbar-nav').css('background', '#32657c'); $('.nav-link').css('color', '#eeeeee'); $('.navbar-brand').css('color', '#eeeeee'); $('#newclients').css('color', '#eeeeee'); $('#newclients').css('border-color', '#eeeeee'); $('#newclients').css('background', 'transparent'); } }); $(function () { MobileNavColor(); }); function MobileNavColor() { if ($('#dvMobile').is(':hidden')) { $('.navbar').css('background', 'transparent'); $('.nav-link').css('color', '#32657c'); $('.navbar-brand').css('color', '#32657c'); $('#newclients').css('border-color', '#32657c'); $('#newclients').css('color', '#32657c'); $('#newclients').css('background', 'transparent'); } else { $('.navbar').css('background', 'transparent'); $('.navbar-nav').css('background', '#32657c'); $('.nav-link').css('color', '#eeeeee'); $('.navbar-brand').css('color', '#eeeeee'); $('#newclients').css('color', '#eeeeee'); $('#newclients').css('border-color', '#eeeeee'); $('#newclients').css('background', 'transparent'); $('.navbar-toggler').css('background', '#32657c'); } } Cosmic XMy scrollTop value is not working? scrollTop
Microsoft's AJAX site. But in a nutshell, two of the client-side script libraries Microsoft has exposed via the Script Manager, i.e., Sys.WebForms.PageRequestManager beginRequest Event and Sys.WebForms.PageRequestManager endRequest Event, provide the ability for us to be notified just before the UpdatePanel charges off to the server to be rewritten, and just as soon as it has returned to the client.By hooking into these two events, we can use a little script to put the scrolltop on any control (ASP or HTML) back where it was before the panel was dragged off to the server. Put this script after the end tag of the UpdatePanel - it has to hold onto the value of the scrolltop variable not get caught up in the refresh cycle.var scrollTop;Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginScript);Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndScript);function BeginScript(sender, args) { var elemnt = document.getElementById('pnlOne'); scrollTop=elemnt.scrollTop;}. . .Round trip takes place:function EndScript(sender, args){ var elemnt = document.getElementById('pnlOne'); elemnt.scrollTop = scrollTop;} And, that's all there is to it. So thanks for reading, and I wish you all a good – Say what?You have more than one Panel that needs to maintain scrolltop? That's easy: write an additional pair of scripts for each Panel.OhhhhhhhhKay. No need to get huffy. . .since the number of panels may change as your app remains in production, let's put all the panels' IDs and their scrolltops into arrays. Now, all you have to do is add any new ID to the first array.Note that at one point, we test to make sure that the Panel exists and is visible. This handles controls that have had their visibility turned off."text/javascript">var pnlArray=['pnlQuarters', 'pnlEngines'];var stArray= new Array();Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginScript);Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndScript);function BeginScript(sender, args) { for (i = 0; ivar elemn = document.getElementById(pnlArray[i]); if (null != elemn) { stArray[i]=elemn.scrollTop; }}. . .Round trip takes place:function EndScript(sender, args){ for (i = 0; ivar elemn = document.getElementById(pnlArray[i]); if (null != elemn) { elemn.scrollTop = stArray[i]; } }} You might also be interested to know that the EndRequest is the absolute last event you can hook into during the request lifecycle; if you would like to be notified earlier - before the content is rendered, you can register with the Sys.WebForms.PageRequestManager.PageLoading. เป็นการใช้ jQuery Css กับ .scrollTop() ในการกำหนดความสูงของ Scollbar ว่ามีความสูงเท่าไหร่ถึงจะขึ้น Scollbar โดยอ้างถึงตำแหน่งในด้านซ้าย scrollTop Syntax .scrollTop() .scrollTop( value ) The scrollTop() method is an inbuilt method in jQuery which is used to return the top vertical position of the scrollbar. Syntax: $(selector).scrollTop(position) The css() method$ (window).scrollTop () vs. $ (document).scrollTop () - Stack
最近の Web サービスでよくある「下までスクロールしたら次のコンテンツを読み込む(オートページャライズ)」を実装するためには、当然ですが「下までスクロールしたかどうか」を検出する必要があります。これが簡単そうに見えて意外と面倒臭く、自分も毎回思い出すのに時間がかかってしまいます。御託はいいから結論を先に言えこれでよさそうfunction getScrollBottom() { var body = window.document.body; var html = window.document.documentElement; var scrollTop = body.scrollTop || html.scrollTop; return html.scrollHeight - html.clientHeight - scrollTop;}以下、解説ですどんな値が取得できるかまず、使いそうな要素document.body body 要素document.documentElement 文書全体を表す要素 (html要素)ややこしいので、これ以降では body と書いてあったら document.body, html と書いてあったら document.documentElement のことだと思ってください。次に、使いそうなプロパティscrollTop 要素内のスクロール量clientHeight 要素の高さscrollHeight 要素内のスクロールできる高さclientHeight と scrollHeight は何が違うんじゃ、って話ですが、要素の高さを超えるくらい要素の内容が多い場合、要素そのものの高さが clientHeight で要素の内容の高さが scrollHeight になります。しかし僕はあまり頭がよくなく、「そんなこと言われてもよくわからん、直感的にわかるようにして!!!」という感じだったので、こういうツールを作りました。 body の高さを変えてみたりすることで、それぞれの値がどう変化するのかがわかると思います。スクロール量を取得するscrollTop には罠があって、ページ全体のスクロール量を取得したい場合は ブラウザによって取得方法が違います。WebKit 系 ( Safari, Chrome 等) や Edge では body.scrollTopIE, Firefox, Opera などでは html.scrollTopブラウザの対応していない方法で取得しようとする(例えば Firefox の document.body.scrollTop)と、必ず 0 が返ってきます。そのため、正しくスクロール量を取得するためにはvar body = document.body;var html = document.documentElement;var scrollTop = body.scrollTop || html.scrollTop;こうする必要があります。ちなみに、scrollTop だけでなく body.scrollHeight もブラウザによって値が変わるのであまり使わないほうがよさそうです。計算する必要な値が取得できたので、あとは計算するだけです。ここで気をつけないといけないのは、コンテンツ量によって body の高さが変わるので body の高さが画面のよりも長い場合と短い場合の両方に対応できるようにしたほうがいいということです。body が長い場合body が長いとき、「ドキュメント全体の高さ」は body.clientHeight または html.scrollHeight で取得することができます。つまり「下からのスクロール位置」はscrollBottom = (ドキュメント全体の高さ) - scrollTop - html.clientHeightこのように求めることができます。body が短い場合body が短いときは、そもそもスクロールしないので「下からのスクロール位置」は常に 0 であってほしいと思います。bodyが長いときの計算式scrollBottom = (ドキュメント全体の高さ) - scrollTop - html.clientHeight この式に当てはめると、期待する scrollBottom は 0 で scrollTop はこの場合は常に 0 なので、(ドキュメント全体の高さ) == html.clientHeight のときに期待する値が得られそうです。(ドキュメント全体の高さ) は body.clientHeight と html.scrollHeight のいずれかだったので、このうち (ドキュメント全体の高さ) == html.clientHeight を満たすのは html.scrollHeight のみとなります。ということで、ドキュメント全体の高さを取得するには html.scrollHeight を使うと良さそうです。つまり、scrollBottom = html.scrollHeight - scrollTop - html.clientHeightこれで「下からのスクロール位置」を求めることができそうです。これをちゃんとした JavaScript に直すと、冒頭に書いたコードになります。オマケvar scrollBottomEvent = window.document.createEvent('UIEvents');scrollBottomEvent.initUIEvent('scrollBottom', true, false, window, 1);window.document.addEventListener('scroll', function() { var body = window.document.body; var html = window.document.documentElement; var scrollTop = body.scrollTop || html.scrollTop; var scrollBottom = html.scrollHeight - html.clientHeight - scrollTop; if ( scrollBottom 0 ) { window.document.dispatchEvent( scrollBottomEvent ); }});こういうカスタムイベントを作っておくとdocument.addEventListener('scrollBottom', function() { // 下までスクロールしたときの処理});下までスクロールしたときのイベント処理がシンプルに書けて便利です。Comments
The Element.scrollTop property gets or sets the number of pixels that an element's content is scrolled vertically. An element's scrollTop value is a measurement of the distance from the element's top to its topmost visible content. When an element's content does not generate a vertical scrollbar, then its scrollTop value is 0. scrollTop can be set to any integer value, with certain caveats: If the element can't be scrolled (e.g. it has no overflow or if the element has a property of "non-scrollable"), scrollTop is 0. scrollTop doesn't respond to negative values; instead, it sets itself back to 0. If set to a value greater than the maximum available for the element, scrollTop settles itself to the maximum value. When scrollTop is used on the root element (the element), the scrollY of the window is returned. This is a special case of scrollTop. Warning: On systems using display scaling, scrollTop may give you a decimal value.A number.In this example, try scrolling the inner container with the dashed border, and see how the value of scrollTop changes. HTML div id="container"> div id="scroller"> p> Far out in the uncharted backwaters of the unfashionable end of the western spiral arm of the Galaxy lies a small unregarded yellow sun. Orbiting this at a distance of roughly ninety-two million miles is an utterly insignificant little blue green planet whose ape-descended life forms are so amazingly primitive that they still think digital watches are a pretty neat idea. p> div>div>div id="output">scrollTop: 0div> CSS #scroller { overflow: scroll; height: 150px; width: 150px; border: 5px dashed orange;}#output { padding: 1rem 0;} JavaScript const scroller = document.querySelector("#scroller");const output = document.querySelector("#output");scroller.addEventListener("scroll", (event) => { output.textContent = `scrollTop: ${scroller.scrollTop}`;}); Result
2025-03-24Classification result to JSON file to build an external API.You may find the Flask official documentation helpful.from flask import Flask, render_template, request, jsonifyimport nltkimport picklefrom nltk.corpus import stopwordsimport refrom nltk.stem.porter import PorterStemmerapp = Flask(__name__)ps = PorterStemmer()# Load model and vectorizermodel = pickle.load(open('model2.pkl', 'rb'))tfidfvect = pickle.load(open('tfidfvect2.pkl', 'rb'))# Build functionalities@app.route('/', methods=['GET'])def home(): return render_template('index.html')def predict(text): review = re.sub('[^a-zA-Z]', ' ', text) review = review.lower() review = review.split() review = [ps.stem(word) for word in review if not word in stopwords.words('english')] review = ' '.join(review) review_vect = tfidfvect.transform([review]).toarray() prediction = 'FAKE' if model.predict(review_vect) == 0 else 'REAL' return prediction@app.route('/', methods=['POST'])def webapp(): text = request.form['text'] prediction = predict(text) return render_template('index.html', text=text, result=prediction)@app.route('/predict/', methods=['GET','POST'])def api(): text = request.args.get("text") prediction = predict(text) return jsonify(prediction=prediction)if __name__ == "__main__": app.run()You can see an index.html file in the previous section, and it’s the home page of the application. Create a folder named "Templates" in the root folder, and create a file "index.html" inside. Now let’s add some content to the page. Fake News Prediction [email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> [email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"> FAKE NEWS PREDICTION API Blog NoteBook Code Source A fake news prediction web application using Machine Learning algorithms, deployed using Django and Heroku. Enter your text to try it. {{text}} Predict {% if result %} Prediction : {{result}} {% endif %} function growTextarea (i,elem) { var elem = $(elem); var resizeTextarea = function( elem ) { var scrollLeft = window.pageXOffset || (document.documentElement || document.body.parentNode || document.body).scrollLeft; var scrollTop = window.pageYOffset || (document.documentElement || document.body.parentNode || document.body).scrollTop; elem.css('height', 'auto').css('height', elem.prop('scrollHeight') ); window.scrollTo(scrollLeft, scrollTop); }; elem.on('input', function() { resizeTextarea( $(this) ); }); resizeTextarea( $(elem) ); } $('.jTextarea').each(growTextarea);The above script creates a web page like this:The fake news detection web app UI (Image by the author)Now you can run your app by typing the following command in your terminal:python3 app.pyYou will be able to run your app locally and have a test on the model.ConclusionIn this tutorial, you built a machine learning model to detect fake news from real ones from scratch and saved the model to build a web application using Flask. The web application is running in your local machine, and you can try to make it public using cloud services such as Heroku, AWS or DigitalOcean. I have deployed mine on Heroku. Feel free to have a try.I hope you enjoy this journey. Welcome to leave a comment and connect with me on Linkedin.
2025-04-12Material ScrollTop ButtonUpgrade instructions 1.x → 2.xLightweight, Material Design inspired button for scroll-to-top of the page (jQuery plugin).Just hit the button to smoothly scroll back to the top of the page. Here's the demo.LightweightMaterial Design inspiredWith ripple effectSmoothly animatedCustomizableWith some useful options...jQuery + CSS, (TypeScript + SCSS)Demo (example)Watch this: yarn or npmyarn add material-scrolltopManual install (download)If you want the latest stable version, get the latest release from the releases page and use dist folder.UsageInclude the files as shown in the code snippets below and you're done.NOTE: The only dependency for this plugin to work is jQuery library (don't forget!)In your add:">link rel="stylesheet" href="dist/material-scrolltop.css" />script src="dist/material-scrolltop.js">script>Then, before your closing tag add: $('body').materialScrollTop();">button class="material-scrolltop" type="button">button>script> $('body').materialScrollTop();script>SettingsOptionTypeDefaultDescriptionrevealElementstringbodyReveal button when scrolling over specific elementrevealPositionstringtopElement position for reveal button ('top' or 'bottom')paddingnumber0Adjusts little ups and downs in scrolling (can be negative number)durationnumber600Determining how long the animation will runeasingstring'swing'Indicating which easing function to use for the transition animate()onScrollEndFunction()falseA function to call once the animation is completeExample (advanced usage) element ... padding: 100, // ... and add padding 100px revealElement: 'header', // Reveal button when scrolling over ... revealPosition: 'bottom', // ... and do it at the end of element duration: 600, // Animation will run 600 ms easing: 'swing', // Do it with swing animation onScrollEnd: function () { // Give me some log when animation ends console.log('This is the end, my only friend, the end...'); },});">$('body').materialScrollTop({ // Scroll to the top of element ... padding: 100, // ... and add padding 100px revealElement: 'header', // Reveal button when scrolling over ... revealPosition: 'bottom', // ... and do it at the end of element duration: 600, // Animation will run 600 ms easing: 'swing', // Do it with swing animation onScrollEnd: function () { // Give me some log when animation ends console.log('This is the end, my only friend, the end...'); },});Foldersmaterial-scrolltop/├── src/| ├── icons/│ | └── top-arrow.svg│ ├── material-scrolltop.scss│ └── material-scrolltop.ts├── dist/| ├── icons/│ | └── top-arrow.svg│ ├── material-scrolltop.css│ └── material-scrolltop.js└── demo/ ├── ... └── index.html └── examples/src/ (for development)TypeScript + SCSS source files.ts, .scsswhich are NOT executable in browserdist/ (for production)JavaScript + CSSexecutable in browser and compiled from src/ folder with command yarn builddemo/ (example page)In this folder you can see an example in real use.CustomizationColors, sizes and stuffUsing SASS (this file in 'src' folder), you can simply edit default styles, colors, position and customize plugin to fit your needs. 👍 (Or just edit directly css stylesheet)Hint: Modify scss file, run yarn build and see the demo.IconsSVGYou can change svg icon in icons/ directory.Custom text or signTurn off svg icon as sass variable: $mst-icon: falseBuild your new stylesheet yarn build (now without svg icon)Put your new sign or text inside html element like this:
2025-04-19(mg) 4 Protein (g) 0 Sugar (g) 0 Serving Size 20 Oz Calories Per Serving 110 Fat (g) 0 Trans Fat (g) 0 Saturated Fat (g) 0 Carbs (g) 28 Fiber (g) 0 Sodium (mg) 0 Protein (g) 0 Sugar (g) 28 Side Sauces Serving Size 2 Oz Calories Per Serving 80 Fat (g) 0 Trans Fat (g) 0 Saturated Fat (g) 0 Carbs (g) 20 Fiber (g) 0 Sodium (mg) 20 Protein (g) 0 Sugar (g) 18 Serving Size 2 Oz Calories Per Serving 40 Fat (g) 0 Trans Fat (g) 0 Saturated Fat (g) 0 Carbs (g) 9 Fiber (g) 0 Sodium (mg) 910 Protein (g) 1 Sugar (g) 8 Serving Size 2 Oz Calories Per Serving 100 Fat (g) 0 Trans Fat (g) 0 Saturated Fat (g) 0 Carbs (g) 4 Fiber (g) 0 Sodium (mg) 90 Protein (g) 5 Sugar (g) 1 Serving Size 8 G Calories Per Serving 0 Fat (g) 0 Trans Fat (g) 0 Saturated Fat (g) 0 Carbs (g) 0 Fiber (g) 0 Sodium (mg) 150 Protein (g) 0 Sugar (g) 0 jQuery(document).ready(function($) { if($(window).width() >= 768){ var $details = $(".category-sidebar"), detailsPos = $details.position().top; $(window).on("scroll", function() { if ($(window).scrollTop() > 260) $details.css("position", "fixed").css("top","auto").css("bottom", 20).css("z-index", -1); else $details.css("position", "relative").css("top", 0); }) } }); -->
2025-04-18