HTML etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
HTML etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

6 Nisan 2022 Çarşamba

HTML Canvas Tag

Örnek
Şöyle yaparız
<canvas id="canvas" width="300" height="300"></canvas>
Kullanmak için şöyle yaparız
let canvas = document.getElementById('canvas');
let ctx = canvas.getContext('2d');

// Create our image
let newImage = new Image();
newImage.src = 'https://fjolt.com/images/misc/202203281.png'

// When it loads
newImage.onload = () => {
    // Draw the image onto the context
    ctx.drawImage(newImage, 0, 0, 250, 208);
}
Açıklaması şöyle
When the image loads (newImage.onload), then we draw the image onto our canvas. To do that, we use ctx.drawImage(). The syntax is shown below.

ctx.drawImage(image, x, y, width, height)

If declared like this, ctx.drawImage() only has 5 arguments:
  • image - the image we want to use, is generated from our new Image() constructor.
  • x - the x position on the canvas for the top left corner of the image.
  • y - the y position on the canvas for the top left corner of the image.
  • width - the width of the image. If left blank, the original image width is used.
  • height - the height of the image. If left blank, the original image height is used.
toDataURL metodu
İmzası şöyle
toDataURL(type, encoderOptions) has two arguments which lets us change the way the canvas is encoded. This lets us save files as other formats, such as jpg.

Those two arguments can be defined as follows:
  • type, which is a filetype, in the format image/png.
  • encoderOptions, which is a number between 0 and 1, defining the image quality. This is only supported by file formats that have lossy compression, like webp or jpg.
Örnek
Şöyle yaparız
// Convert our canvas to a data URL
let canvasUrl = canvas.toDataURL("image/jpeg", 0.5);
console.log(canvasUrl);

// Outputs 
// "data:image/jpeg;base64,/9j/...
Örnek
Şöyle yaparız
let canvas = document.getElementById('canvas');
let ctx = canvas.getContext('2d');

// Canvas code goes here 
// ...

document.getElementById('download').addEventListener('click', function(e) {
    // Convert our canvas to a data URL
    let canvasUrl = canvas.toDataURL();
    // Create an anchor, and set the href value to our data URL
    const createEl = document.createElement('a');
    createEl.href = canvasUrl;

    // This is the name of our downloaded file
    createEl.download = "download-this-canvas";

    // Click the download button, causing a download, and then remove it
    createEl.click();
    createEl.remove();
});

27 Eylül 2021 Pazartesi

HTML Header Tag

Örnek
Şöyle yaparız
<body>
  <header>
    <img src="/static/logo.png" alt="Logo">
    <nav>
      <a href="/">Main page</a>
    </nav>
  </header>
  <main>
    <article>
      <h1>Title</h1>
      <p>Content</p>
    </article>
  </main>
  <footer></footer>
</body>

7 Eylül 2021 Salı

HTML Embed Tag

Örnek - PDF
Şöyle yaparız
<embed id="plugin" type="application/x-google-chrome-pdf" src="..." 
...
>

25 Temmuz 2021 Pazar

HTML Picture Tag

HTML Img tag yetersiz kalıyor. Açıklaması şöyle
However, with the development of devices of various screen sizes, resolutions, and complex user requirements, questions have begun to raise about its responsiveness and ability to be used in multi-device applications.
Yani iki temel sebep var. 
1. Resolution Switching
2. Art Direction : 

Bu iki sebepten herhangi birisi tek başına HTML Picture tag'i seçmek için yeterli değil. Sadece Resolution Switching gerekiyorsa, HTML Img tag te kullanılabilir.

Resolution Switching
HTML Img tag ile olan problem şöyle
Suppose you use a simple Img tag for high-res images. In that case, that same image is used in each device your application runs, and indeed it will result in performance issues in devices with lower screen resolutions like mobile devices.
Art Direction
Orientation yani Landscape veya Portrait demek

source/media Alanı
Örnek
Şöyle yaparız
<picture>
<source media="(orientation: landscape)" srcset="land-small-car-image.jpg 200w, land-medium-car-image.jpg 600w, land-large-car-image.jpg 1000w" sizes="(min-width: 700px) 500px, (min-width: 600px) 400px, 100vw"> <source media="(orientation: portrait)" srcset="port-small-car-image.jpg 700w, port-medium-car-image.jpg 1200w, port-large-car-image.jpg 1600w" sizes="(min-width: 768px) 700px, (min-width: 1024px) 600px, 500px"> <img src="land-medium-car-image.jpg" alt="Car"> </picture>
Açıklaması şöyle
If the screen orientation is landscape browser will show the images from the first image set, and if the orientation is portrait browser will use the second set. 
En alttaki img için açıklaması şöyle
The last img tag is there for backward compatibility for browsers that do not support picture tags.
Örnek
Şöyle yaparız
<picture>
     <source media="(max-width: 767px)" ....>
     <source media="(min-width: 768px)" ....>
</picture>
source/srcset Alanı
Örnek
Şöyle yaparız
<picture>
   <source
      srcset="small-car-image.jpg 400w,
              medium-car-image.jpg 800w,
              large-car-image.jpg 1200w"
      sizes="(min-width: 1280px) 1200px,
             (min-width: 768px) 400px,
             100vw">
   <img src="medium-car-image.jpg" alt="Car">
</picture>
Örnek - type
Şöylee yaparız
<picture>
  <source srcset="test.avif" type="image/avif">
  <source srcset="test.webp" type="image/webp">
  <img src="test.png" alt="test image">
</picture>
Açıklaması şöyle
The above example includes three image types from avif, webp, and png formats. First, the browser will try avif format, and if that fails, it will try webp format. If the browser does not support both of these, it will use png image.

27 Nisan 2021 Salı

HTML Iframe Tag

Giriş
Açıklaması şöyle
iFrame provides “sandboxing” to isolate content of the embedded frame from the parent web page, thus ensuring that information is not accessible or cannot be manipulated through various exploits by malicious individuals.
iframe içindeki Bağlantı
Açıklaması şöyle. Yani iframe kendi bağlantısını yapar
While it may seem natural to think that if one page visually envelops another, there may be something similar happening with the underlying connections, this is not the case.

Your browser creates distinct HTTPS connections to host1 and host2, and both in (more-or-less) the same manner. 
Örnek
Şöyle yaparız
<iframe width="420" height="315" src="https://www.youtube.com/watch?v=dQw4w9WgXcQ">
</iframe>

10 Haziran 2020 Çarşamba

HTML Input Tag

Giriş
Açıklaması şöyle.
The <input> element is one of the most interesting HTML elements we have access to. Depending on the attributes it can be a text field, a range slider, a file selector a button and many more.
< Karakterinden Sonra Boşluk Olamaz
Açıklaması şöyle.
No, you cannot have a space immediately after the < (less-than sign) in an HTML element's opening start tag.
autocomplete Attribute
Açıklaması şöyle.
There are many autocomplete values available, covering everything from names and addresses to credit cards and other account details. For sign up and login there are a few autocomplete values that stand out as useful hints: username, email, new-password, current-password.
Örnek
Şöyle yaparız
<input autocomplete="on" name="inputName">
class Attribute
Eğer bu alana btn değeri atanırsa düğme gibi görünür.

Örnek
Elimizde şöyle bir css olsun
.disabled {
  background: #ccc;
  cursor: not-allowed;
  border-width: 1px;
}
Şöyle yaparız.
<input type="text" readonly="readonly" class="disabled" />
<input type="password" readonly="readonly" class="disabled" />
disabled Attribute
Şöyle yaparız.
input type="text" value="{{user.name}}" readonly>
// In this case you can get post values  

<input type="text" value="{{user.name}}" disabled>
// In this case you can not get post values  
inputmode Attribute
Açıklaması şöyle.
The inputmode attribute changes the keyboard the browser should display without changing the meaning of the data the field collects. We want our <input> to receive text input, but from the numeric keyboard. So instead, add inputmode="numeric"

<input type="text" name="token" id="token" inputmode="numeric" />

inputmode has a number of other values, including "tel" for telephone numbers, "email", "decimal", "url", "search" and "none" in case you want to render your own keyboard.... 

Browser support for inputmode is good for mobile operating systems these days, but a couple of years ago it was in the wilderness. For older browsers there is another trick to trigger the numeric keyboard and include a bit of extra validation for free.
onChange Attribute
Şöyle yaparız.
render() {
  return (
    <div>
      <input type="text" name="word" value={this.state.field}
             onChange={this.handleChangeField} />
      {this.state.field}
    </div>
  );
}
pattern Attribute
Açıklaması şöyle.
The pattern attribute allows you to validate the contents of an <input> using a regular expression. Using the pattern [0-9]* tells the browser that we only accept numbers in the field and also triggers the number pad in browsers without inputmode support.
readOnly Attribute
readonly değerini alabilir. Şöyle yaparız.
<input type="text" readonly="readonly" disabled value="{user.name}}">
type Attribute
checkbox,hidden,text, time değerlerini alabilir.
checkbox Tipi
Örnek
Checkbox için şöyle yaparız.
<input id="more" type="checkbox" /> <label for="more">more</label>
date Tipi
Örnek
Şöyle yaparız.
<input type="date" id="tgt">
Değere erişmek için şöyle yaparız.
document.getElementById('tgt').addEventListener('change', function() {
    console.log(Object.prototype.toString.call(this.valueAsDate));
});
veya şöyle yaparız.
let strValue = document.getElementById("myDate").value; 
let dateValue = new Date(strValue);
file Tipi
Örnek
Şöyle yaparız
<form onSubmit="check(event)">
  <input id="name" class="btn" type="file" name="pic" multiple>
  <button class="btn btn-primary" type="submit" id="submit" name="submit">UPLOAD</button>
</form>
hidden Tipi
Örnek
Gizli alan için şöyle yaparız.
<input type="hidden" id="thisField" name="inputName" value="hiddenValue">
Servlet içinde bu alana erişmek için şöyle yaparız.
String hidden = request.getParameter("inputName");
password Tipi
Örnek
Elimizde şöyle bir kod olsun.
validateNumber(event) {
  const keyCode = event.keyCode;

  const excludedKeys = [8, 37, 39, 46];

  if (!((keyCode >= 48 && keyCode <= 57) ||
    (keyCode >= 96 && keyCode <= 105) ||
    (excludedKeys.includes(keyCode)))) {
      event.preventDefault();
  }
}
Şifre için şöyle yaparız.
<input type="password" placeholder="Enter Mobile no" formControlName="mobile_no"
  (keydown)="validateNumber($event)">
Örnek
Şifre için şöyle yaparız.
<form action="javascript: alert('alright');">
<div>
  <input type="password" 
         pattern="^[0-9]{10}$"
         inputmode="numeric"
         minlength="10" maxlength="10"
         placeholder="Enter Mobile no"
         required title="Ten digits required.">
  <input type="submit">
</div>
</form>
text Tipi
Örnek
Metin girdi için şöyle yaparız.
<input type="text" name="email" placeholder="Your Email" id="userInput"><br>
time Tipi
Örnek
Saat için şöyle yaparız.
<input type=time value=00:00 autofocus>
value Attribute
Girdi kutusundaki değere erişmek için kullanılır.
Örnek
Elimizde şöyle bir kod olsun.
<input id="letters" type="text" name="entry">
Girilen değere erişmek için şöyle yaparız.
var tileLetters = document.getElementById("letters").value;  //value instead of text