<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alex</title>
    <description>The latest articles on DEV Community by Alex (@lestrae).</description>
    <link>https://dev.to/lestrae</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F599699%2F3da95491-e708-4f98-be27-7957b478ec51.jpg</url>
      <title>DEV Community: Alex</title>
      <link>https://dev.to/lestrae</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lestrae"/>
    <language>en</language>
    <item>
      <title>My first attempt to make script for Lazy-load images</title>
      <dc:creator>Alex</dc:creator>
      <pubDate>Sat, 07 Jan 2023 09:08:42 +0000</pubDate>
      <link>https://dev.to/lestrae/my-first-attempt-to-make-script-for-lazy-load-images-5f06</link>
      <guid>https://dev.to/lestrae/my-first-attempt-to-make-script-for-lazy-load-images-5f06</guid>
      <description>&lt;p&gt;This is very simple script, what make images to load only when they appear in your browser viewport. Why it's important you can read here &lt;a href="https://web.dev/browser-level-image-lazy-loading/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Script written on plain JavaScript, and it's weight &amp;lt;1 kb.&lt;/p&gt;

&lt;p&gt;In html code it uses the same idea, as other similar scripts. Let's say you have image:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;img src='myCat.jpg'&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Change attribute &lt;em&gt;src&lt;/em&gt; to &lt;em&gt;data-src&lt;/em&gt;, so it will look like:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;img data-src='myCat.jpg'&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Script, when image appear in viewport will put value from &lt;em&gt;data-src&lt;/em&gt; to newly created &lt;em&gt;src&lt;/em&gt; attribute.&lt;/p&gt;

&lt;p&gt;In first line of the script I put in array all the elements what I got by using &lt;em&gt;getElementsByTagName()&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;var myImages = [...document.getElementsByTagName('img')];&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is because I don't know how to delete elements from the &lt;em&gt;HTMLCollection&lt;/em&gt;, which I get using clearly &lt;em&gt;document.getElementsByTagName('img')&lt;/em&gt;. So I put it into array, and can easily manipulate them.&lt;/p&gt;

&lt;p&gt;I used:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;document.addEventListener('scroll'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;and function inside it, to check if image appear in viewport.&lt;/p&gt;

&lt;p&gt;Inside of this function - simple &lt;em&gt;for...&lt;/em&gt; cycle, which, using method &lt;em&gt;getBoundingClientRect()&lt;/em&gt; will check, if image come in sight of viewport.&lt;/p&gt;

&lt;p&gt;By using &lt;em&gt;myImages.splice(i, 1)&lt;/em&gt; I remove already lazy-loaded image from array. When array empty - script stops:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;if (myImages.length == 0) {&lt;br&gt;
        document.removeEventListener('scroll', lazyLoad);&lt;br&gt;
    }&lt;/code&gt;&lt;/p&gt;




&lt;p&gt;I don't know how good or bad this script, but it works.&lt;br&gt;
If someone find it useful I'll be happy 😊&lt;/p&gt;

&lt;p&gt;&lt;a href="https://lestrangeqq.github.io/lazyLoad/"&gt;Demo&lt;/a&gt; || &lt;a href="https://github.com/lestrangeqq/lazyLoad"&gt;Github&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Script to Mark Text in article</title>
      <dc:creator>Alex</dc:creator>
      <pubDate>Fri, 19 Mar 2021 18:40:16 +0000</pubDate>
      <link>https://dev.to/lestrae/script-to-mark-text-in-article-49n5</link>
      <guid>https://dev.to/lestrae/script-to-mark-text-in-article-49n5</guid>
      <description>&lt;p&gt;Hi guys! My first post here, and this is my script what let user to mark text of the article that he find interesting or useful.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UeMcL6a1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zw82m5d0d8tfhvgs60sc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UeMcL6a1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zw82m5d0d8tfhvgs60sc.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On text selection under cursor will appear block with 2 buttons - &lt;b&gt;mark text&lt;/b&gt; and &lt;b&gt;copy text&lt;/b&gt;. &lt;/p&gt;

&lt;p&gt;If user clicked on 'mark text' - selected text will be surrounded with &amp;lt;mark&amp;gt; tag and highlighted. Also all text, what user marked will be collected into list in bottom right corner:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lN0IKJ1I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ui18x7ecb50zb6nu5t6l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lN0IKJ1I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ui18x7ecb50zb6nu5t6l.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nothing special with &lt;b&gt;"copy text"&lt;/b&gt; button - it just copies text :)&lt;/p&gt;

&lt;p&gt;Idea for this script comes to my mind when I worked on site for sea mans, where articles are big and very hard to read.&lt;/p&gt;

&lt;p&gt;JSFIDDLE &lt;a href="https://jsfiddle.net/Lestrae/po931gmq/12/"&gt;https://jsfiddle.net/Lestrae/po931gmq/12/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I know one bug in this script, but I hope you don't find it :D&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>css</category>
    </item>
  </channel>
</rss>
