Scrolltop css
Author: s | 2025-04-25
เป็นการใช้ 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
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. เป็นการใช้ 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 Element.scrollLeft and Element.scrollTop. Setting the element .scrollLeft and .scrollTop properties is the same as calling Element.scrollTo() with the coordinates. It'll respect the CSS scroll css class to disable scrolling .lock-scroll{ position: fixed; width: 100%; height: 100%; } javascript code to fix the scrollTop jump after applying the css class: It polyfills scroll(), scrollTo(), scrollBy(), scrollIntoView() and the CSS scroll-behavior. It does not support smooth scrolling by setting scrollLeft / scrollTop and it does not support the CSS:.hidden { display: none; } Here's the code for conditionally showing the button: The scrollTop (MDN Reference) value that we are getting from the respective animate - scrollTop in Css. Ask Question Asked 6 years, 1 month ago. Modified 6 years, 1 month ago. Viewed 10k times There is a native CSS feature that controls scroll I think you are missing the 'height' CSS property. Mentioning an appropriate pixel value as height, and implementing 'scrollTop()' method on the id of the container upto its 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 [email protected]('/', 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 [email protected]('/', 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.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-04-13Classification 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 [email protected]('/', 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 [email protected]('/', 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-22Material 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-03-27(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-13There 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 the
2025-04-08Hi 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 X
2025-03-29